|
DEELX 正则引擎编程示例:判断数字
判断一个字符串是否全由数字组成。
表达式
方法
MatchExact
代码
#include "deelx.h"
int test_all_number(const char * string)
{
// declare, you can use
'static' if your regex does not change
CRegexpT <char> regexp("\\d+");
// test
MatchResult result = regexp.MatchExact(string);
// matched or not
return result.IsMatched();
}
int main(int argc, char * argv[])
{
char * str1 = "12345";
char * str2 = "12345 abcde";
printf("'%s' => %s\n", str1, (test_all_number(str1) ? "yes" : "no"));
printf("'%s' => %s\n", str2, (test_all_number(str2) ? "yes" : "no"));
return 0;
} |
|
|
|