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.
>Solution :
You can use so called "non-consuming" expression ("(?=*)
"):
(?=[^\s])\W
Example: