Say I want to find in a string the word 'car' and after that it can be anything any lenght but the word 'hotel' and after that it can be anything any lenght and then the word 'hello' should come.
How would that perl regex look like?? How do I write to not allowing a word like 'hotel' inside this string?
preg_match - How do I...?
Moderator: General Moderators
Re: preg_match - How do I...?
Perl? Methinks you're asking in the wrong site.
Wrong forum, at the very least, since there's a dedicated regex forum.
strpos is your friend, for both "can't have the word 'hello'" and "must have 'car', then somewhere after a 'hello' but no 'hotel'".
Wrong forum, at the very least, since there's a dedicated regex forum.
strpos is your friend, for both "can't have the word 'hello'" and "must have 'car', then somewhere after a 'hello' but no 'hotel'".
Code: Select all
$car = strpos($string, "car");
$hotel = strpos($string, "hotel", $car);
$hello = strpos($string, "hello", $car);
if ($car !== false && $hotel === false && $hello !== false) {
// valid
}