/^(.+?) (is|was) an? (.+?)$/ is my current regular expression for PHP’s preg_match function.
But I don’t want it to match the sentence: "what is a dog" or "who is a dog". So I have to somehow specify that the words ‘what’ and ‘who’ should not be matched for the first group.
How do I do this?
Thanks.
Edit: Just to clarify, I want it to match sentences like "Buddy is an animal" and "jsbvsjvdhbjsbjhv is a dog", etc.
You could use a negative lookbehind, right before the
(is|was)group:Note that I removed the ungreedy quantifier from the last subpattern – since you want to match as much as possible to get to the end of the string, it’s inefficient to tell it to match as little as possible.