Trying a few things with negative and positive look-behind, can't really get exactly what I want. Went through this SO question as well: Regex match a substring if that substring is not preceded by a specific string?
What I want is just a "yes this entire string should be considered" and a "no, ignore this entire string", because of these substring matches. The post above will help me match the substring, but if the negative words precede the substring, it's still a match, you can see my tests here: https://regex101.com/r/aqn1gO/2
What I'm trying to do is have a regex match for the substring i need
, but ignore cases where it's not a request, but more a question. The examples are:
Where 1.
and 2.
should match, but 3.
, 4.
, and 5.
should not, even though there's an i need
in there.
One approach might be then to negate those with do
or should
followed by any chars and a must positive lookahead with i need
:
^(?=.*i need.*)(?!.*should.*i need.*|.*do.*i need.*).*$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.