user2531854
user2531854

Reputation: 866

Include and Exclude Words in one expression

I need a regex expression that only searches for the word size - non-case-sensitive, but excludes Drawing.size and FontSize

So it could find the words:

size
Size
BSize
SizeA

but it would exclude the words like:

Drawing.size
FontSize

Upvotes: 1

Views: 473

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

You can use a negative look ahead to exclude the prefix words:

/^(?:(?!(?:Drawing\.|Font)).)*size.*$/im

See demo https://regex101.com/r/kV2nR2/1

Note that the flag i makes your regex case insensitive and m is multiline flag and makes the anchors ^ and $ match the start and end of the regex for each line.

Upvotes: 1

Related Questions