Originally Posted by
TheDenominater
I'm trying to do some input parsing using <regex.h> , but I can't get it work quite the way I want.
In this case I'm trying to match a line that starts with any amount of whitespace, then a '#'.
Does "any amount of whitespace" mean zero or more whitespace characters? If so the "+" should really be a "*", as in
Code:
pattern == "^[[:blank:]]*#";
The code segment below is executed inside of isComment() every time a line of input is read.
Code:
regex_t* temp;
temp = malloc(sizeof(regex_t));
regcomp(temp, "[:blanc:]+#", 0);
Instead compile the regexp once and execute many times by moving the code into the function that calls isComment(), as in
Code:
regex_t *temp = (regex_t *) malloc(sizeof(regex_t));
regcomp(temp, "^[[:blank:]]*#", 0);
isComment(temp, line);