summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-07-28 00:24:13 +0200
committerTyge Løvset <[email protected]>2022-07-28 12:39:34 +0200
commit281a4148d9143260c614c92e81d3484103479761 (patch)
tree6661f8f41c416c0120d677fbaffb07f9b3eabbc9 /examples
parent18392a1f49bb742fce3e28bb8196b2a64ea07219 (diff)
downloadSTC-modified-281a4148d9143260c614c92e81d3484103479761.tar.gz
STC-modified-281a4148d9143260c614c92e81d3484103479761.zip
VERSION 3.8 RC. Added cregex with "final" API + docs. README.md updated with links to cregex, coption.
crandom.h: fixed "stc64_with_seq doesn't use seq argument #31" thanks to funny-falcon. Removed deprecated funcs. Added tags for v3.6 and v3.7.
Diffstat (limited to 'examples')
-rw-r--r--examples/regex_replace.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/examples/regex_replace.c b/examples/regex_replace.c
index 3dcb965d..35b3c696 100644
--- a/examples/regex_replace.c
+++ b/examples/regex_replace.c
@@ -33,13 +33,18 @@ int main()
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"));
- cregex_drop(&re);
- printf("euros: %s\n", cstr_str(&str));
+ /* Shows how to compile RE separately */
+ c_autovar (cregex re = cregex_from(pattern, 0), cregex_drop(&re)) {
+ if (cregex_captures(&re) == 0)
+ continue;
+ /* European date format. */
+ cstr_take(&str, cregex_replace(input, &re, "$3.$2.$1"));
+ printf("euros: %s\n", cstr_str(&str));
+
+ /* Strip out everything but the matches */
+ cstr_take(&str, cregex_replace_re(input, &re, "$3.$2.$1;", NULL, 0, cre_r_strip));
+ printf("strip: %s\n", cstr_str(&str));
+ }
/* Wrap all words in ${} */
cstr_take(&str, cregex_replace_p("[52] apples and [31] mangoes", "[a-z]+", "$${$0}"));