summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-01-16 17:43:19 +0100
committerTyge Løvset <[email protected]>2022-01-16 17:43:19 +0100
commit5bd8089e0c3c0a4f48c40d7011d30132c921408a (patch)
tree6f58ab316d3537d49b638ac5def5de05f8e3b326 /examples
parent12fc6070378f5f78b07f7ac1efdadfdb8534ff27 (diff)
downloadSTC-modified-5bd8089e0c3c0a4f48c40d7011d30132c921408a.tar.gz
STC-modified-5bd8089e0c3c0a4f48c40d7011d30132c921408a.zip
Added cregex_compile() to reuse a cregex object (using realloc)). Major optimizations when using ^ and $ (removed 3 strlen calls).
Diffstat (limited to 'examples')
-rw-r--r--examples/regex2.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/regex2.c b/examples/regex2.c
index 5509baa5..512f7e58 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -4,7 +4,7 @@
int main()
{
- const char* inputs[] = {"birthday: 1964-12-05", "https://en.cppreference.com/w/cpp/regex/regex_search", "!123abcabc!"};
+ const char* inputs[] = {"date: 2024-02-29 leapyear day", "https://en.cppreference.com/w/cpp/regex/regex_search", "!123abcabc!"};
const char* patterns[] = {"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|[12][0-9]|0[1-9])",
"(https?:\\/\\/|ftp:\\/\\/|www\\.)([0-9A-Za-z-@:%_+~#=]+\\.)+([a-z]{2,3})(\\/[\\/0-9A-Za-z-\\.@:%_+~#=\\?&]*)?",
"!((abc|123)+)!",
@@ -15,14 +15,16 @@ int main()
{
re = cregex_new(patterns[i]);
csview m;
+ printf("input: %s\n", inputs[i]);
if (cregex_find_sv(&re, inputs[i], &m))
{
- printf("input: %s\n", inputs[i]);
c_forrange (j, cregex_capture_size(re))
{
csview cap;
- bool res = cregex_capture_sv(&re, j, &cap);
- if (res) printf(" submatch %zu: " c_PRIsv "\n", j, c_ARGsv(cap));
+ if (cregex_capture_sv(&re, j, &cap))
+ printf(" submatch %zu: " c_PRIsv "\n", j, c_ARGsv(cap));
+ else
+ printf(" FAILED index %zu\n", j);
}
puts("");
}