1

I'm trying to figure out a regular expression syntax that will match the following strings:

  • The City has not fully complied with its obligations under the Prior Undertaking
  • The School District has not fully complied with its obligations under the Prior Undertaking
  • The District has not fully complied with its obligations under the Prior Undertaking

So far, I have the following: The (?!.*(no|never|not)).{0,50}? has not fully complied with its obligations under the Prior Undertaking

But, it is not working on https://regex101.com. Thanks for your help.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Pepa
  • 159
  • 8
  • 1
    what do you want to accomplish with `(?!.*(no|never|not)).{0,50}?` ? Currently there is not match because this lookahead `(?!.*(no|never|not))` fails in all sentences. Can you update the question with what it should not match? – The fourth bird Aug 17 '22 at 15:51
  • Hi. I was playing around on regex101.com. ```the (?!.*(no|never|not)).{0,50} may``` matched with ```the damn may n```. So, I thought it could be useful. I'm not sure, sorry. – Pepa Aug 17 '22 at 15:58
  • Oh, I think I got this. ```The (?!.*(yummy|tummy)).{0,50} has not fully complied``` is working. – Pepa Aug 17 '22 at 16:06
  • Are you looking for this? `The (?:(?!no|never|not).){0,50}? has not fully complied with its obligations under the Prior Undertaking` https://regex101.com/r/okAjXh/1 – The fourth bird Aug 17 '22 at 16:08
  • What if `yummy` or `tummy` occur farther than fifty chars? Maybe you need `The (?!.{0,45}(yummy|tummy)).{0,50} has not fully complied`? – Wiktor Stribiżew Aug 17 '22 at 16:08

1 Answers1

2

Your current pattern does not match any of the example strings, because this part The (?!.*(no|never|not)) asserts from that position that either no never and not should not occur to the right.

But for all 3 example strings, one of the words is present.

What you might do is write the pattern using a tempered greedy token approach:

The (?:(?!no|never|not).){0,50}? has not fully complied with its obligations under the Prior Undertaking

This part (?:(?!no|never|not).){0,50}? now repeat 0-50 times as least as possible matching a single character asserting what is not directly to the right is either of the listed words.

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70