Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for selecting words ending in 'ing' unless

I want to select words ending in with a regular expression, but I want exclude words that end in thing. For example:

everything
running 
catching 
nothing

Of these words, running and catching should be selected, everything and nothing should be excluded.

I've tried the following:

.+ing$

But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.

Solutions that work in Python or R would be helpful.

like image 850
Todd Shannon Avatar asked Nov 18 '25 02:11

Todd Shannon


1 Answers

In python you can use negative lookbehind assertion as this:

^.*(?<!th)ing$

RegEx Demo

(?<!th) is negative lookbehind expression that will fail the match if th comes before ing at the end of string.

Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:

\w+(?<!th)ing\b
like image 99
anubhava Avatar answered Nov 20 '25 19:11

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!