Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <regex.h>
- int match (const char *string, char *pattern) {
- int status;
- regex_t re;
- // Compile the pattern for extended REGEX with only Y/N feedback (validates it too)
- if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
- return -1;
- }
- // See if pattern validates input
- status = regexec(&re, string, (size_t) 0, NULL, 0);
- // Free allocated memory
- regfree(&re);
- // Output result on standard-out
- if (status == 0) {
- fprintf(stdout, "Match!\n");
- } else {
- fprintf(stdout, "No match!\n");
- }
- return 0;
- }
- int main (void) {
- const char string[3] = {0xFF, 0xFF, 0x0};
- char *pattern = "^\\xFF\\xFF$";
- printf("Pattern = %s\n", pattern);
- if (match(string, pattern) != 0) {
- fprintf(stderr, "Err: Something went wrong in match!\n");
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement