How to match the $ special character using regular expression in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
#include <regex.h>

int match(const char *string, const char *pattern) {
    regex_t regex;
    int result;

    regcomp(&regex, pattern, REG_EXTENDED);
    result = regexec(&regex, string, 0, NULL, 0);
    regfree(&regex);

    return result == 0;
}

int main() {
    const char *s = "It's only $20.00 today";
    
    int matchFound = match(s, "\\$");
    
    printf("%d\n", matchFound);

    return 0;
}



/*
run:

1

*/

 



answered Feb 16, 2025 by avibootz
edited Feb 16, 2025 by avibootz
...