Match “After” if it doesn’t have an an -ing word after it

I want to match After if there isn’t an -ing word after it (and before a comma). So there shouldn’t be an -ing word between After and the comma.

Desired match (bold):

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

I thought this regex would do it:

bAfterb.*(?!w+ing)+,

But it’s also matching After if there isn’t an -ing word after it:

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

https://regexr.com/683bv

Why is this and how to fix it?

Answer

Try this regex

Matches only sentence from After and a comma, where there’s no word with -ing after the wo

Just a lazy quantifier to the .+ (which instead of w+in your regex) does the trick

bAfter (?!.+?ing).*?,

(And also a lazy quantifier after the second .*, just in case if there’s 2 commas in the same sentence)

Output:

img

Regex101 Demo

Tell me if its not working for you…