With POSIX, you can only search for a given regular expression; you
can't match it. To do this, you must first compile it in a
pattern buffer, using regcomp
.
To compile a pattern buffer, use:
int regcomp (regex_t *preg, const char *regex, int cflags)
preg is the initialized pattern buffer's address, regex is the regular expression's address, and cflags is the compilation flags, which Regex considers as a collection of bits. Here are the valid bits, as defined in `regex.h':
REG_EXTENDED
regcomp
sets preg's syntax
field accordingly.
REG_ICASE
regcomp
sets preg's translate
field to a translate table which ignores case, replacing anything you've
put there before.
REG_NOSUB
no_sub
field; see section POSIX Matching,
for what this means.
REG_NEWLINE
.
)) doesn't match a newline.
[
... ]
and [^
... ]
)) matches a newline.
^
)) matches the empty string immediately after a newline,
regardless of how REG_NOTBOL
is set (see section POSIX Matching, for
an explanation of REG_NOTBOL
).
^
)) matches the empty string immediately before a newline,
regardless of how REG_NOTEOL
is set (see section POSIX Matching,
for an explanation of REG_NOTEOL
).
If regcomp
successfully compiles the regular expression, it
returns zero and sets *pattern_buffer
to the compiled
pattern. Except for syntax
(which it sets as explained above), it
also sets the same fields the same way as does the GNU compiling
function (see section GNU Regular Expression Compiling).
If regcomp
can't compile the regular expression, it returns one
of the error codes listed here. (Except when noted differently, the
syntax of in all examples below is basic regular expression syntax.)
REG_BADRPT
REG_BADBR
REG_EBRACE
REG_EBRACK
REG_ERANGE
REG_ECTYPE
REG_EPAREN
REG_ESUBREG
REG_EEND
REG_EESCAPE
REG_BADPAT
REG_ESIZE
REG_ESPACE
Go to the first, previous, next, last section, table of contents.