Javascript regex for symbol but not space

I want to test a string for a symbol (e.g. $%^&*) so I use the following which works well:

/[W+]/.test(string)

But, a space also matches this. What I really want is to test for a symbol but not a space, I’m trying the following but a space is matching

/[WS+]/.test(string)

Is there a better way to do this?


Source: regex

Leave a Reply