deelx正则例子

deelx正则例子

贪婪匹配
#include <stdio.h>
#include "deelx.h" 
int main(int argc, char * argv[])
{   
char text[] = "bbbbbbbba():asfsdgdsg()+sf+ssfd";
static CRegexpT <char> regexp("a.*d"); //贪婪匹配
MatchResult result = regexp.Match(text);
while ( result.IsMatched() )
{   
printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());
result = regexp.Match(text, result.GetEnd());
}
getchar();
return 0;
}

result:  a():asfsdgdsg()+sf+ssfd

非贪婪匹配
#include <stdio.h>
#include "deelx.h" 
int main(int argc, char * argv[])
{   
char text[] = "bbbbbbbba():asfsdgdsg()+sf+ssfd";
static CRegexpT <char> regexp("a.*?d"); //贪婪匹配
MatchResult result = regexp.Match(text);
while ( result.IsMatched() )
{   
printf("%.*s\n", result.GetEnd() - result.GetStart(), text + result.GetStart());
result = regexp.Match(text, result.GetEnd());
}
getchar();
return 0;
}

result:  a():asfsd

posted on 2013-04-16 14:54  大灰羊  阅读(176)  评论(0)    收藏  举报