Assume the following word sequence
BLA text text text text text text BLA text text text text LOOK text text text BLA text text BLA
What I would like to do is to extract the text from BLA to LOOK, but the BLA which is the closest to look. I.e. I would like to get
BLA text text text text LOOK
How should I do that using regular expressions? I got one solution which works, but which is exteremely inefficient.
BLA(?!.*?BLA.*?LOOK).*?LOOK
Is there a better and more performant way to achieve matching this pattern?
What I would like to do is: I would like to match BLA, then forward lookahead until either positive fordward lookahead with LOOK or negative lookahead with BLA. But I don't know a way to put this into a regular expression.
As a engine I use re in python.
(?s)BLA(?:(?!BLA).)*?LOOK
Try this. See demo.
Alternatively, use
BLA(?:(?!BLA|LOOK)[\s\S])*LOOK
To be safer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With