tags:

views:

2034

answers:

4

How can I include a blank space ' ' and a comma ',' in this simple regular expression?

\w{1,64}

\w corresponds to: [A-Za-z0-9_], viz avery char between a-z (case sensitive/insensitive), numbers between 0-9 and the underscore. I need to add space and comma to this. I've been trying directly whit

[A-Za-z0-9_, ]

but this did allow characters that I didn't want, like: \ / < > [ ] . : ; @ ^ so I've choosen \w. Any help will be appraised :)

+11  A: 

[\w ,]{1,64}

dsm
+5  A: 

Create a character class using \w:

[\w ,]{1,64}

Edit:

The reason your other test allowed those characters is because you put A-Za-Z instead of A-Za-z

Greg
A: 

many thanks :D

Giancarlo
A: 

BTW: The character class you tried didn't work because you did "a-Z" instead of "a-z".

Paul Tomblin