tags:

views:

72

answers:

3

Hi, I need a regular expression for accepting alpha numerics and special charecters also

like : abc & def12

thanks in advance Nagesh

A: 

Hi, not got a specific answer, but regexlib.com has come in handy for me.

Breandán
or http://www.zytrax.com/tech/web/regex.htm
Ruben Bartelink
This one is handy for testing your regex: http://www.gskinner.com/RegExr/
stiank81
+1  A: 

^[\w]+$ this regex will match all alphanumerics, if you want to match some other chars as well just specify them in the [] brackets, i.e. if you wan't to also match ampersand you will have ^[\w&]+$ regex, if you wan't to match white characters as well (tabs, spaces, line feeds, carriage returns) you add \d and end up with ^[\w&\s]+$ and so on until you have all your special characters handled.

RaYell
Bart Kiers
Yeah, that was a typo. Fixed it already.
RaYell
+2  A: 

This might be the syntax you are looking for /^[a-zA-Z0-9&:\/ ]+$/, insert any other characters you want to match between the square brackets.

I would recommend you to read up on regular expressions if you intend to use them in the future, check out this tutorial http://perldoc.perl.org/perlretut.html

adamse