Reputation: 42813
I need that if string contains symbols .
AND @
that print yes, queue symbols does not matters, important that in string will be this symbols at least one times, I need make this using regexp.
I write:
if (preg_match("#(\@.*\.)|(\..*\@)#",$str)) {
echo "yes";
}
But I doubt that can write more easy pattern for this
Upvotes: 0
Views: 83
Reputation: 27305
Perhaps its a bit easier without a regex.
if(strpos($str, ".") !== false || strpos($str, "@") !== false) {
echo "yes";
}
Then you don't need the regex is perhaps a bit faster. Then you only search if a character is in a string.
Upvotes: 0
Reputation: 27307
You can use lookahead to separate the two conditions:
^(?=.*\.)(?=.*@)
The start-of-string anchor is not needed, but it helps performance.
Upvotes: 2
Reputation: 13450
use this regex (?=.*\.)(?=.*@).+
(?=.*\.) dot exists
(?=.*@) @ exists
.+ any string
Upvotes: 2