Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Created August 1, 2023 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerrorJack/af962c4f85cf613ed47a565e7ac39e5e to your computer and use it in GitHub Desktop.
Save TerrorJack/af962c4f85cf613ed47a565e7ac39e5e to your computer and use it in GitHub Desktop.
#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(&regex_compiled, pattern, REG_EXTENDED)) {
return 1; // Return 1 if the regex failed to compile
}
return_code = regexec(&regex_compiled, target_string, 0, NULL, 0);
regfree(&regex_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