Finding spaces with preg_match

If I want to match alpha-numeric, underscore, dash and space

How would I represent the space in

preg_match(“/[a-zA-Z0-9_-]/”, $value)

just putting in a space doesn’t seem to work.


\s represents a space

Excellent, thanks

not exactly - \s represents any type of whitespace (spaces, tabs, line feeds).

you could simply type the space into the pattern i.e.:

/[a-zA-Z0-9_\- ]/

or use \040 for clarity i.e.


by the way, \w is alpha-numeric and underscores, so you could simply to:

/[\w\- ]/