From 0516aa3ae823ed9a22b2c5f776948c8447c32c31 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Mon, 10 Apr 2023 14:04:15 +0200 Subject: Made cregex docs example online. --- docs/cregex_api.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/cregex_api.md b/docs/cregex_api.md index 0c532c60..9a15a869 100644 --- a/docs/cregex_api.md +++ b/docs/cregex_api.md @@ -96,13 +96,14 @@ cregex_drop(&re1); If an error occurs ```cregex_compile``` returns a negative error code stored in re2.error. ### Getting the first match and making text replacements + +[ [Run this code](https://godbolt.org/z/z434TMKfo) ] ```c -#define i_extern // include external utf8 and cregex functions implementation. +#define i_extern // include external cstr, utf8, cregex functions implementation. #include -#include int main() { - const char* input = "start date is 2023-03-01, and end date is 2025-12-31."; + const char* input = "start date is 2023-03-01, end date 2025-12-31."; const char* pattern = "\\b(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)\\b"; cregex re = cregex_from(pattern); @@ -116,7 +117,7 @@ int main() { // Lets change all dates into US date format MM/DD/YYYY: cstr us_input = cregex_replace(&re, input, "$2/$3/$1"); - printf("US input: %s\n", cstr_str(&us_input)); + printf("%s\n", cstr_str(&us_input)); // Free allocated data cstr_drop(&us_input); -- cgit v1.2.3