6:50 PMC regex "Invalid regular expression"
If you are thrown at legacy C code and see "Invalid regular expression" from regexec -- don't rush to blame your regular expression. The root cause for the "Invalid regular expression" could be improper set of flags used with the regexec call.
You have a simple regex. regcomp does compile the regex just fine. But when you get to regexec - it fails with "Invalid regular expression", and the regexec call uses some flags like this:
regexec(compiled_regex, subj_string, 0, NULL, REG_NOSUB | REG_ICASE); // the flags are WRONG!
Get rid of improper flags.
The only acceptable flags to the regexec are:
REG_NOTBOL - Do not regard the beginning of the specified string as the beginning of a line; more generally, don’t make any assumptions about what text might precede it.
REG_NOTEOL - Do not regard the end of the specified string as the end of a line; more generally, don’t make any assumptions about what text might follow it.
REG_NOSUB, REG_ICASE or whatever else - are supposed to be used with regcompFor details see regex.h and/or Matching a Compiled POSIX Regular Expression.
|Total comments: 0|