Regex to search for special characters in a string with some exceptions

I was simply answered a similar (but not exact) question. Now I need help with the question mentioned below.

I want to write a regular expression that matches a character if it is not a word, not a number, and not a star (*). Thus, the characters [0-9][az][AZ] * should not match, and the rest should.

I tried to write [\W[^*]] but it did not work.

+6
regex
source share
4 answers

Try this instead:

 [^\w\*] 
+14
source share
 [^\w\*] 

Simple enough.

+7
source share

The simplest regular expression that matches a single character that is not one of those that you describe does not depend on any particular regular expression extensions would be:

 [^0-9a-zA-Z *] 
+4
source share

Please try the following regular expression:

 [\W_] 
0
source share

All Articles