Click to See Complete Forum and Search --> : Regular Expression to match alphanumeric


adwaitjoshi
September 20th, 2005, 11:09 PM
I think when I use \w it will match a alphanumeric value but what happens is if my sting is this
asd@#$@# it still matches that. I need to modify this to match ONLY a-z, A-Z, 0-9 and _ and this has to be true for EACH character in the string. how can I do it?
Adwait

PeejAvery
September 20th, 2005, 11:32 PM
Wow, that is very vague. What exactly are you trying to do and what language are you writing this in?

khp
September 21st, 2005, 01:12 AM
I would suspect that your problem is that you are not tying the expression off at the ends. If your entire expression is '\w' it should match the 'a' character, in your string.
To match an entire string containing only alphanumeric characters write ^\w+$


^ matches the beginning of the string,
\w matches alphanumeric
+ repeat match one or more times
$ matches the end of a string.