/((?:(?:is|will) (?!is))[^<?]+)/i
Test sentences:
I dont want it to match the first sentence and I want it to match the second.(which it does atm)
I am trying to learn how I can return the whole regex as false if the word after "is|will" is "is", but it keeps matching and eventually finds a match in example number one. I am kind of new to regex, so all help is appreciated.
This is what the match looks like:
Thanks in advance
Your expression seems fine, but you need to anchor it so that it starts matching from the beginning of the text. You can use ^
at the start of the regex.
/^((?:(?:is|will) (?!is))[^<?]+)/i
Without the anchor, the regex engine tries to find a match anywhere in the string. In the case of the first sentence, it can match the word is
as the first word in the expression, and then the rest of the expression matches.
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.