samuel
samuel

Reputation: 321

Pattern to match any word that does not end with any of letters a,b,c?

Using Regex.

I have this to find the words that end with those letters:

\S+[abc]\b

But I need all the words that has these letters in any position but not in the end.

Upvotes: 0

Views: 326

Answers (3)

Alon
Alon

Reputation: 4952

the ^ character is regex for not (when used in a character group) so a slight modification to your regex will produce : \S+[^abc]\b : mach one or more non space characters and then any character besides a,b or c whose located at the word boundary

Upvotes: 6

Wim
Wim

Reputation: 11252

If [abc] must be somewhere in the word (except the end), you need this:

\S*[abc]\S*[^abc]\b

If [abc] doesn't need to be anywhere, Alon's solution is enough:

\S+[^abc]\b

Upvotes: 3

Anne
Anne

Reputation: 480

a ^ to signify NOT a, b or c should work:

\S+[^abc]\b

Upvotes: 0

Related Questions