|
DEELX 正则引擎编程示例:连续查找
列举一段文本中所有的带小数的数字。
表达式
方法
Match
第一种代码
#include "deelx.h"
int main(int argc, char * argv[])
{
// text
char * text = "12.5, a1.1, 0.123, 178";
// declare, you can use
'static' if your regex does not change
CRegexpT <char> regexp("\\b\\d+\\.\\d+");
// loop
MatchResult result = regexp.Match(text);
while( result.IsMatched() )
{
printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());
// get next
result = regexp.Match(text, result.GetEnd());
}
return 0;
} |
第二种代码
#include "deelx.h"
int main(int argc, char * argv[])
{
// text
char * text = "12.5, a1.1, 0.123, 178";
// declare, you can use
'static' if your regex does not change
CRegexpT <char> regexp("\\b\\d+\\.\\d+");
// prepare
CContext * pContext = regexp.PrepareMatch(text);
// loop
MatchResult result = regexp.Match(pContext);
while( result.IsMatched() )
{
printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());
// get next
result = regexp.Match(pContext);
}
// release
regexp.ReleaseContext(pContext);
return 0;
} |
|
|
|