Created
August 1, 2023 08:55
-
-
Save TerrorJack/af962c4f85cf613ed47a565e7ac39e5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <regex.h> | |
#include <stdlib.h> | |
int foo() { | |
const char *target_string = "hello wasm"; | |
const char *pattern = "wasm"; | |
regex_t regex_compiled; | |
int return_code; | |
if (regcomp(®ex_compiled, pattern, REG_EXTENDED)) { | |
return 1; // Return 1 if the regex failed to compile | |
} | |
return_code = regexec(®ex_compiled, target_string, 0, NULL, 0); | |
regfree(®ex_compiled); // Free up the memory allocated for the regex | |
if (!return_code) { | |
return 0; // Return 0 if the pattern is found in the target_string | |
} else if (return_code == REG_NOMATCH) { | |
return 2; // Return 2 if the pattern is not found | |
} else { | |
return 3; // Return 3 for any other type of error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment