primary0
primary0

Reputation: 1180

Regular expression to match all but certain characters in class

What's the best way match all punctuation characters in the class [[:punct:]] except @ and #?

Upvotes: 2

Views: 570

Answers (2)

Platinum Azure
Platinum Azure

Reputation: 46183

You can use negative lookahead:

(?:(?![#\@])[[:punct:]])+

Upvotes: 9

GetSet
GetSet

Reputation: 532

[[:punct:]] is equivalent to [!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]

See: http://www.regular-expressions.info/posixbrackets.html

You can simply extract the symbols you don't want: [!"$%&'()*+,-./:;<=>?[\]^_`{|}~]

Upvotes: 1

Related Questions