Reputation: 35734
I'm using regular expressions to match any number of white space characters. Is there a difference between the following?
" *"
"\s*"
Are there special cases where either would cause an issue?
Upvotes: 4
Views: 1418
Reputation:
" *"
will only match zero or more of the [SPACE] character and only the [SPACE] character.
"\s*"
will match zero or more of ANY whitespace character ( SPACE, TAB, FORMFEED, etc. ).
Therefore they are not equivalent expressions. \s
is what you want usually, especially since you can't readily see whitespace characters by definition.
Upvotes: 14
Reputation: 382132
This is the difference between the regular space () and any space (space, tab, line breaks, etc.).
See reference here.
Upvotes: 3