prof chaos
prof chaos

Reputation: 444

regex exclude for group

This is a regex that matches everything i want to exclude, which is words like abba, trillion etc.

[a-z]*([a-z])([a-z])\2\1[a-z]*

Is there something like [^] which i can use in this situation?

Upvotes: 1

Views: 264

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626845

You can use

\b(?![a-z]*([a-z])([a-z])\2\1[a-z]*\b)[a-z]+\b

See regex demo (I think you need a case-insensitive modifier with this regex.)

Since you want to match words only, you need to use \b word boundary, and to exclude specific words, you need to use a negative lookahead anchored to the leading word boundary.

Upvotes: 1

Related Questions