Robbie
Robbie

Reputation: 716

regex match except end of string

For example, if I have 3 words:

throw
growing
plows

I'm wanting something that will return only words without 'ow' on the end:

growing
plows

Basically the exact opposite of:

/ow$/

So it will only return the words when 'ow' does NOT show up on the end.

Upvotes: 1

Views: 1496

Answers (4)

bobble bubble
bobble bubble

Reputation: 1

Right, when 'ow' does NOT show up at the end of the word:

/\b\w+(?<!ow)\b/i

Use word boundaries \b and word characters \w together with lookbehind (?<!ow)

Upvotes: 0

Murtuza Z
Murtuza Z

Reputation: 6017

Python code:

lst = ["throw","growing","plows"]

for item in lst:
    if not str.endswith(item.lower(), "ow"):
        print item

Upvotes: 0

Avinash Raj
Avinash Raj

Reputation: 174874

Use negative lookahead.

^(?!.*ow$).+

Upvotes: 1

vks
vks

Reputation: 67988

^.*(?<!ow)$

You can use lookbehind here.See demo.

https://regex101.com/r/cT0hV4/4

Upvotes: 1

Related Questions