Case:
- ehello goodbye hellot hello goodbye
- ehello goodbye hello hello goodbye
I want to match line 1 (only has ‘hello’ once!)
DO NOT want to match line 2 (contains ‘hello’ more than once)
Tried using negative look ahead look behind and what not… without any real success..
A simple option is this (using the multiline flag and not dot-all):
First, check you don’t have ‘hello’ twice, and then check you have it at least once.
There are other ways to check for the same thing, but I think this one is pretty simple.
Of course, you can simple match for
\bhello\band count the number of matches…