|
DEELX Engine Examples: Test Email
To test whether a string is valid email address.
Regular Expression
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$ |
Method
MatchExact
Code
#include "deelx.h"
int test_email(const char *
string)
{
// declare, you can use
'static' if your regex does not change
CRegexpT <char> regexp("^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\\w]*[0-9a-zA-Z])*\\.)+[a-zA-Z]{2,9})$");
// test
MatchResult result = regexp.MatchExact(string);
// matched or not
return result.IsMatched();
}
int main(int argc, char *
argv[])
{
char * str1 = "bob@smith.com";
char * str2 = "bob@.com";
printf("'%s' => %s\n", str1, (test_email(str1) ?
"yes" : "no"));
printf("'%s' => %s\n", str2, (test_email(str2) ?
"yes" : "no"));
return 0;
} |
|
|
|