Answer the question
In order to leave comments, you need to log in
Where is the error in the regular expression?
Hello!
This code returns false:
if (regex_match("[email protected]", regex("/^[a-zA-Z0-9._-][email protected][a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$/")))
{
return true;
}
else
{
return false;
}
Answer the question
In order to leave comments, you need to log in
UPD: In fact, it's all about the extra slashes " / regexp_here / "
Instead \\.
, use \.
https://regex101.com/r/kY0uS0/2
But in general, this is not serious. This thing will not miss a bunch of valid addresses.
Examples of regular expressions are
more impressive www.regular-expressions.info/email.html
stackoverflow.com/questions/46155/validate-email-a...
Here is a "training" regular expression for you: \[email protected]\S+
In fact, only the presence of a dog and "some" characters is checked before and after her.
https://regex101.com/r/cG7dW0/1
if (regex_match("[email protected]", regex("^[a-zA-Z0-9._-][email protected][a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$")))
cout << "match" << endl;
else
cout << "no match" << endl;
You should replace it with \\.
AND \.
as a general recommendation: for simplicity, you should use special characters, for example "/^[\w.-][email protected][\w.-]+\\.[a-z]{2,4}$/i"
, where \w
is equivalent to [a-zA-Z0-9_]
, and the "i" flag indicates that you should ignore the case of characters when searching for matches.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question