Problem with regular expression
-
Hi, i have to validate my password with this rules 1.i can enter any alpha numeric charcter 2.I can enter anything in a valid speical character set so i write my regular expression like this [a-zA-Z0-9 + strspecialCharacterString +] and to avoid special meaning of speical character i am adding \ in front of every special character.Now my problem in wen i use an _ in my pattern ie some thing like "*_<" it is not working.It throws an error below "parsing "[\*\_\<]" - Unrecognized escape sequence \_." if i give \\ instead of \ it is working.can any body help me in sorting out this problem? Thanks in advance shally
sdf
-
Hi, i have to validate my password with this rules 1.i can enter any alpha numeric charcter 2.I can enter anything in a valid speical character set so i write my regular expression like this [a-zA-Z0-9 + strspecialCharacterString +] and to avoid special meaning of speical character i am adding \ in front of every special character.Now my problem in wen i use an _ in my pattern ie some thing like "*_<" it is not working.It throws an error below "parsing "[\*\_\<]" - Unrecognized escape sequence \_." if i give \\ instead of \ it is working.can any body help me in sorting out this problem? Thanks in advance shally
sdf
Hi, The underscore character is not a special character inside a regex, so it should NOT be escaped by a backslash; and when you prefix it by two backslashes, you are actually adding a single backslash to the list of acceptable characters. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
Hi, The underscore character is not a special character inside a regex, so it should NOT be escaped by a backslash; and when you prefix it by two backslashes, you are actually adding a single backslash to the list of acceptable characters. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused:
-
hi, Thanks a lot for your my answer.But i have one doubt.Why error is throwing only if we use underscore character."!,@,:" etc are not special character.But if i use them in my pattern no error is throwing. Why is it like this? Shally
sdf
These are the characters that have a special meaning in a regex expression:
$ ^ { [ ( | ) * + ? \
If you need one of them literally, then you must escape it with a backslash; all other characters (including _ ! @ : ) are regular characters, just like a thru z and 0 thru 9. :)Luc Pattyn [Forum Guidelines] [My Articles]
Fixturized forever. :confused: