RegEx: matches any character other than a word and without numbers except

To match any character other than a word and without numbers (special characters), I use this: [\\W\\D] . What should I add if I want to also ignore some specific characters? Say, we emphasize.

+6
source share
1 answer

First of all, you should know that \W equivalent to [^a-zA-Z0-9_] . So you can change the current regular expression like this:

 [\\W] 

This will automatically take care of \D

Now, if you want to ignore any other character, say & (underscore is already excluded in \W ), you can use a negative character class:

 [^\\w&] 
+11
source

Source: https://habr.com/ru/post/951766/


All Articles