Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
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:

\bAfter\b.*(?!\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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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...

about 4 years ago · Juan Pablo Isaza Report

0

The pattern you tried:

  • Using .* will first match the whole line, then it will backtrack to match the first encountered comma, so it will also match all comma's in between.
  • It can match the first encountered comma because this part (?!\w+ing), asserts that from the current position there are no word chars followed by ing and then match a , But \w does not match a comma so the asserting will always be true.

You can exclude matching a comma in the negative lookahead using a negated character class, and then also match until the first occurrence of a comma afterwards.

\bAfter\b(?![^,\n]*ing)[^,\n]*,

In parts, the pattern matches:

  • \bAfter\b Match the word After between word boundaries
  • (?![^,\n]*ing) Negative lookahead to assert that from the current position there is no occurrence of ing without crossing a comma
  • [^,\n]*, Match optional chars except a comma (or a newline if you don't want to cross lines)

Regex demo

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!