Introduction
This example demonstrates searching for multiple matches within a search text (similar to the functionality provided by Perl's "/g"l modifier. This example matches each line in the text and prints the result of each search.
Demonstrates
This example demonstrates the following RGX features:
-
Loading and invoking the p6IRegex component interface.
-
The use the P6MODIFIER_MULTILINE modifier.
-
Using the offset and length to increment the search position.
-
Use of the getCaptureText() method.
Also see the CConsoleStream example for and example of creating the optional debug p6IDataStream which is passed into p6loader.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include "p6rgx.h"
#include "cconsolestream.h"
using namespace P6R;
namespace {
static const P6CHAR gszSearch[] =
"one\ntwo\nthree\nfour\nfive";
{
if(
P6SUCCEEDED(err = cpRegex->compile(
"^([a-zA-Z0-9_., \\t]+)[\\n\\r]*",P6MODIFIER_NULL))) {
do {
cpRegex->search(&gszSearch[i],P6MODIFIER_MULTILINE,&matchOffset,&matchLength);
if(matchLength) {
cpRegex->getCaptureText(1,&capOffset,&capLength);
cpStr->formatString(&szBuf[0],
P6CHARCNT(szBuf),NULL,
"Match: %1$:%2$ [ %3$ ]\n",&args[0],3);
printf(&szBuf[0]);
i += matchOffset+matchLength;
}
} while(matchLength != 0);
}
}
}
}
return err;
}
}
int main(int argc,char *argv[])
{
{
{
err = runRegex( cpDataStream );
}
else printf("ERROR: Failed to initialize the loader [ %x ]\n", err );
}
else printf( "ERROR: Failed to create CConsoleStream [ %x ]\n", err );
return err;
}