Jump to content

Problem with W3Schools Regexp Object reference, [A-z]


John Curley

Recommended Posts

I am an occasional user of javascript who relies on W3Schools reference and tutorials, which are great. However I recently wasted over an hour tracking a problem due to a misleading description in the Regexp Object reference, namely the line:

 

[A-z] Find any character from uppercase A to lowercase z

 

What isn't mentioned is that the regular expression [A-z] also finds other things like brackets, backslash and underline. This caused my program to complain about missing brackets. I suggest the problem line read instead:

 

[a-zA-Z] Find any character from uppercase A to lowercase z

 

Link to comment
Share on other sites

Not sure what your problem is. It doesn't match brackets.

 

http://jsfiddle.net/RPLUm/

 

Anything in a bracket says "match these characters". Then you define what characters you want to be matched. If you want to match actual brackets you need to escape the bracket with a backslash ''.

Edited by MrFish
Link to comment
Share on other sites

Oh. Well I didn't know that. Probably a good idea to include that in the tut if it's not already.

 

You should probably just use w, d, s, etc. I've never actually used A-z or any variation of it. Just my opinion.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...