summaryrefslogtreecommitdiffhomepage
path: root/examples/regex_replace.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-07-22 17:44:27 +0200
committerTyge Løvset <[email protected]>2022-07-22 17:44:27 +0200
commitc1ecb1ac75664b0771993582fda9919e52d03a2d (patch)
tree8206cc820313f1f1f8ae450111268e6de6811cb4 /examples/regex_replace.c
parent29d9d1d96d8a37f6d7e24dc170aa08a40f0f1559 (diff)
downloadSTC-modified-c1ecb1ac75664b0771993582fda9919e52d03a2d.tar.gz
STC-modified-c1ecb1ac75664b0771993582fda9919e52d03a2d.zip
Switched from "\\" as replacement group prefix to '$'. cregex_replace() changed: removed the last two args.
Diffstat (limited to 'examples/regex_replace.c')
-rw-r--r--examples/regex_replace.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/examples/regex_replace.c b/examples/regex_replace.c
index 2bb9517f..21252236 100644
--- a/examples/regex_replace.c
+++ b/examples/regex_replace.c
@@ -26,23 +26,23 @@ int main()
printf("fixed: %s\n", cstr_str(&str));
/* US date format, and add 10 years to dates: */
- cstr_take(&str, cregex_replace_pe(input, pattern, "\\1/\\3/\\2", add_10_years, 0, 0));
+ cstr_take(&str, cregex_replace_pe(input, pattern, "$1/$3/$2", add_10_years, 0, 0));
printf("us+10: %s\n", cstr_str(&str));
/* Wrap first date inside []: */
- cstr_take(&str, cregex_replace_pe(input, pattern, "[\\0]", NULL, 1, 0));
+ cstr_take(&str, cregex_replace_pe(input, pattern, "[$0]", NULL, 1, 0));
printf("brack: %s\n", cstr_str(&str));
/* European date format. Show how to compile RE separately */
cregex re = cregex_from(pattern, 0);
if (cregex_captures(&re) == 0)
continue;
- cstr_take(&str, cregex_replace(input, &re, "\\3.\\2.\\1", NULL, 0));
+ cstr_take(&str, cregex_replace(input, &re, "$3.$2.$1"));
cregex_drop(&re);
printf("euros: %s\n", cstr_str(&str));
/* Wrap all words in {} */
- cstr_take(&str, cregex_replace_p("[52] apples and [31] mangoes", "[a-z]+", "{\\0}"));
+ cstr_take(&str, cregex_replace_p("[52] apples and [31] mangoes", "[a-z]+", "$${$0}"));
printf("curly: %s\n", cstr_str(&str));
}
}