|
DEELX Engine Examples: Match Continuously
To list each decimal fraction in a string.
Regular Expression
Method
Match
Code Example 1
#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;
} |
Code Example 2
#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;
} |
|
|
|