/regex.c
C | 35 lines | 17 code | 6 blank | 12 comment | 4 complexity | 29b509e35a607d52200892b6ae9cd032 MD5 | raw file
- /*
- * regex.c
- *
- * Created on: Nov 6, 2010
- * Author: Zhuruev Konstantin
- */
- #include <regex.h>
- #include <unistd.h>
- /*
- * Match string against the extended regular expression in
- * pattern, treating errors as no match.
- *
- * Return 1 for match, 0 for no match.
- */
- int
- match(const char *string, char *pattern)
- {
- int status;
- regex_t re;
- if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
- return(0); /* Report error. */
- }
- status = regexec(&re, string, (size_t) 0, NULL, 0);
- regfree(&re);
- if (status != 0) {
- return(0); /* Report error. */
- }
- return(1);
- }