Positiv and negative Regular Expressions in one preg_match()?

Question

i would like to put a positive and a negative regular expressions in one preg_match(). Is that possible?

I use these if Condition.

if ( preg_match('/bot|crawler|spider|/i', $user_agent) )
{
            if ( preg_match('/google|duckduck|yandex|baidu|yahoo|/i', $user_agent) )
            {
                $post['url'] = $url;
            }
            else
            {
                // nothing
            }
}

And would like to simplify the code to only one preg_match …something like these

if ( preg_match('/bot|crawler|spider|/^(?!/google|duckduck|yandex|baidu|yahoo|/).i', $user_agent) )
      
   $post['url'] = $url;

}

But it is not working that way

0
soo29 4 months 0 Answers 12 views 0

Leave an answer