• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

287
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?

almost 3 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.
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error