I have seen similar problems but I cant quite get them to work for my scenario.
I am trying to use regex to find an optional wildcard between 2 strings. Here is an example of the strings that the regex does find correctly: not happy
if the string was: not very happy
The code must still match both cases.
The code I have is:
/\b(?<=not(*?).)happy\b/
(happy
and very
would be variables)
Any help pointing me in the right direction would be very much appreciated.
Some tweaking may be required, but this would match up to two words in between "not" and "happy":
/not(?:\s+\w+){0,2}\s+happy/
This ...
/not +([^ ]* +)?happy/
And feel free to replace ? with {0,2} (for example) to match up to 2 words between not and happy.