Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would you combine a "negate" wildcard [^] with another wild card?

I have the string "Programming. Is! Amazing.", and I want to learn how I can write a regex pattern using the wild cards \s to ignore the spaces and \W to match only the . and !.

[^\s]\W

The idea with the pattern is to negate white spaces with [^\s] and match . and ! by using \W., so that the result becomes .!.

The pattern is obviously not correct, but I would like to learn if there is a syntax that could give me the desired effect by basically combining [^] with another wildcard.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use so called "non-consuming" expression ("(?=*)"):

(?=[^\s])\W

Example:

https://regexr.com/7ffrt

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading