diff options
| author | 2026-11-08 05:23:31 +0000 | |
|---|---|---|
| committer | 2026-11-08 05:24:55 +0000 | |
| commit | 3f36aca66e1ac6c872300059e8db691a473614d4 (patch) | |
| tree | 48c65f463c487d281c7c4091c7ba01dd4a2ff8f1 /src/regex.c | |
| download | lab-02-master.tar.gz | |
Diffstat (limited to 'src/regex.c')
| -rw-r--r-- | src/regex.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/regex.c b/src/regex.c new file mode 100644 index 0000000..866c6e8 --- /dev/null +++ b/src/regex.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include "regex.h" | ||
| 2 | #include <regex.h> | ||
| 3 | #include <stddef.h> | ||
| 4 | |||
| 5 | static regex_t compiled; | ||
| 6 | const char *regex_pattern = "^\\(https\\?://\\)\\?docs\\.\\(new/*\\|google\\.com/document/d/[-0-9A-Z_a-z]\\+\\(/\\(edit\\|view\\|preview\\|copy\\|mobilebasic\\|template/preview\\)\\?\\)\\?\\(?\\([^%]\\|%[0-9A-Fa-f][0-9A-Fa-f]\\)*\\)\\?\\)$"; | ||
| 7 | |||
| 8 | static void __attribute__((constructor)) | ||
| 9 | init (void) | ||
| 10 | { | ||
| 11 | regcomp (&compiled, regex_pattern, REG_NOSUB); | ||
| 12 | } | ||
| 13 | |||
| 14 | bool | ||
| 15 | regex_match (const char *string) | ||
| 16 | { | ||
| 17 | return !regexec (&compiled, string, 0, NULL, 0); | ||
| 18 | } | ||
