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

355
Views
Match "And" if the preceding sentence has an "and"

Basically, I want to do this:

Text and text text. Text text. And text. (Don't match this "And.")
Text and text text. And text. (Match this "And.")

Right now, I have this regex: .*\b(and)\b.*\. And. But it matches both And's in the example above: https://regexr.com/65k52

How to modify this regex so it only matches And if the previous sentence has and?

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

0

If you want to use . + whitespace as a sentence separator sequence you can use

(?=\S)[^.]*(?:\.(?!\s)[^.]*)*?\band\b[^.]*(?:\.(?!\s)[^.]*)*\.\s+And\b
(?=\S)(?:[^.]|\.(?!\s))*?\band\b(?:[^.]|\.(?!\s))*\.\s+And\b

See the regex demo #1 and regex demo #2. Details:

  • (?=\S) - next char must be a non-whitespace
  • (?:[^.]|\.(?!\s))*? - zero or more (but as few as possible) occurrences of any one char other than . or a . that is not immediately followed with whitespace
  • \band\b - whole word and
  • (?:[^.]|\.(?!\s))* - zero or more (but as many as possible) occurrences of any one char other than . or a . that is not immediately followed with whitespace
  • \. - a dot
  • \s+ - one or more whitespaces
  • And\b - a whole word And.
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!