Jasper Zhou
Jasper Zhou

Reputation: 527

Using Regular expression to match string that not end with 's

I am trying to use regex to match strings that not end with 's, I wrote a regex like this: .*[^('s)$]$, but it seems that this regex also cannot match a string that ends with a single s, like cats or dogs, can somebody help? thx

I am using egrep, I have tried like

^(?!.*'s$).*

or

.*(?<!ab)$

but it seems these not working well

Upvotes: 1

Views: 139

Answers (1)

anubhava
anubhava

Reputation: 784888

Look-around assertions are traditionally not supported in grep. You may be able to usegrep -v` here:

grep -v "'s$" file

-v option is used for inver-match which is used to return lines are those not matching any of the specified patterns.


However do note in in gnu-grep you can use experimental -P option to use advanced PCRE features such as lookahead and lookbehind assertions.

Upvotes: 1

Related Questions