tags:

views:

41

answers:

2

I write regular expression for alphanumerics, but it is not taking space.
I want space (whitespace between characters).
I write like this:

^[a-zA-Z0-9_]*$
+1  A: 

There is the \s escape sequence that mean "whitespace".

Change you regex to this (adding whitespace to the list of characters):

^[a-zA-Z0-9_\s]*$

As noted by Alex, \w stands for word characters, so you could shorten it further:

^[\w\s]*$

See this handy cheat sheet.

Oded
+1  A: 

Maybe

^[\w\s]*$

would be shorter?

\w means word characters (letters, digits, and underscores).

I prefer this cheat sheet (print).

Alex