1

Assume the following word sequence

BLA text text text  text text text BLA text text text text LOOK BLA text my text text LOOK text text text LOOK BLA text text LOOK

What I would like to do is find all occurrences of "my text" and all the strings up to the BLA immediately before "my text" and the LOOK immediately after "my text"

The output I expect is:

BLA text my text text LOOK

I tried this but what it does is extract all patterns starting with BLA and ending in LOOK not only the pattern containing "my text"

BLA(?:(?!BLA|LOOK)([\s\S]))*?LOOK
plaminenko
  • 15
  • 5
  • Depending on what exactly you want, try `r'BLA(?:\W+(?!(?:BLA|LOOK)\b)w+)*LOOK'` but this assumes you are looking for these two as independent words. Going forward, try to specify your requirements in full detail. – tripleee Aug 15 '22 at 16:06
  • @tripleee the regex you have provided does not seem to work. Check out here: https://regex101.com/r/4J8GnV/1 – plaminenko Aug 15 '22 at 16:28
  • Sorry, there's a backslash missing, that should obviously be `\w+` and there should be another `\W+` immediately before the final `LOOK`. But again, you will get better answers if you take care to explain exactly what you need. – tripleee Aug 15 '22 at 16:38
  • @tripleee I edited it. Hope it is clearer now. – plaminenko Aug 15 '22 at 17:06

1 Answers1

3
BLA(?:(?!BLA).)*?my text.*?LOOK

https://regex101.com/r/C7yxVo/1

If I`m getting your intentions right

cool_cat
  • 58
  • 3