Question

How can I write a Regular Expression to match,

    a string which does not contain the underscore "_".
Was it helpful?

Solution

/^[^_]*$/

The [^] syntax means "do not include any of these characters".

OTHER TIPS

To match a character that is not an underscore you'd use [^_] (the ^ means "not"). So to match a whole string you'd do something like this:

/[^_]+/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top