The text is processed in the most recent project, so you use the gun regular expression, which is POSIX-style. We usually use Perl style, so it might be a bit of a habit to start with. The detailed distinction can be seen on the wiki:
Http://en.wikipedia.org/wiki/Regular_expression
The header file is the regex.h that can see the interface he provides. Here are 3 functions and one structure:
Reference
int regcomp (regex_t *compiled, const char *pattern, int cflags)
int regexec (regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr [], int eflags)
void regfree (regex_t *compiled)
typedef struct {
regoff_t rm_so;
regoff_t rm_eo;
} regmatch_t;
Regcomp compiles the parameter pattern to compiled, which is to say that the string is compiled as a regular expression.
and the parameter cflags can be the following 1 or several combinations:
reg_extended
Use the extended POSIX Regular Expressions.
Reg_icase
Ignore case
Reg_nosub
does not store matching results, only returns whether the match was successful.
Reg_newline
You can match line wrapping.
Regexec performs a match. Compiled is the regular expression that was just compiled, string is the string to be matched, and nmatch is the length of the subsequent structure array (regmatch_t). Matchptr is an array of regmatch_t ( Which is where the $0,$1, like Perl, are stored. The Eflag parameter can be 1 or more of the following.
Reg_notbol
Will say ^ as a generic character match, not the beginning of a line
Reg_noteol
Will say $ as a generic character match, not end of line
RegFree you need to release the regular expression after each run. Compiled is a regular expression that needs to be freed.
The Rm_so in regmatch_t is the starting position of the matching character, and the Rm_eo is the ending position.
Say so much, actually use very simple:
Reference
POSIX Regexp Compilation: Using regcomp to prepare to match.
Flags for POSIX Regexps: Syntax variations for regcomp.
Matching POSIX Regexps: Using regexec to match the compiled pattern that you get from regcomp.
Regexp Subexpressions: Finding which parts of the string were matched.
Subexpression Complications: Find points of which parts were matched.
Regexp Cleanup: Freeing storage; reporting errors.