I just switched to the built-in regex functionality using regex.h (to be cross platform). And with the following simple regex, many valid inputs, such as as@abc.com now fail (where ab@abc.com still works fine):
^[^@\s]+@[^@\s]+\.[^\s\.@]+$
The calling code is:
return Common::regexMatch("^[^@\\s]+@[^@\\s]+\\.[^\\s\\.@]+$", userInput);
And here's the implementation:
#import "regex.h"
bool Common::regexMatch(const string& regex, const string& text) {
//return [[NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding] isMatchedByRegex:[NSString stringWithCString:regex.c_str() encoding:NSUTF8StringEncoding]];
regex_t re = {0};
if (regcomp(&re, regex.c_str(), REG_NOSUB | REG_EXTENDED | REG_ICASE) != 0)
return false;
int status = regexec(&re, text.c_str(), (size_t)0, NULL, 0);
regfree(&re);
if (status != 0)
return false;
return true;
}
It's baffling that it's discriminating based on a different letter, when the regex pattern has no letter specifications in it at all. And it's very consistent on which inputs it doesn't like. TIA.