Skip to content

Commit

Permalink
Made cregex docs example online.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyge Lovset committed Apr 10, 2023
1 parent 75a1e92 commit 0516aa3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/cregex_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stc/cregex.h>
#include <stc/cstr.h>

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);
Expand All @@ -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);
Expand Down

0 comments on commit 0516aa3

Please sign in to comment.