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 POSIX Matching,
for what this means.
REG_NEWLINE
REG_NOTBOL
is set (see POSIX Matching, for
an explanation of REG_NOTBOL
).
REG_NOTEOL
is set (see 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 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
**
in
a**
are invalid. As another example, if the syntax is extended
regular expression syntax, then the repetition operator *
with
nothing on which to operate in *
is invalid.
REG_BADBR
-1
in a\{-1
is invalid.
REG_EBRACE
a\{1
is missing a close-interval operator.
REG_EBRACK
[a
is missing a close-list operator.
REG_ERANGE
z
that collates lower than
does its starting point a
in [z-a]
is invalid. Also, the
range with the character class [:alpha:]
as its starting point in
[[:alpha:]-|]
.
REG_ECTYPE
foo
in [[:foo:]
is
invalid.
REG_EPAREN
a\)
is missing an open-group operator and \(a
is missing a close-group operator.
REG_ESUBREG
\2
that refers to a nonexistent
subexpression in \(a\)\2
is invalid.
REG_EEND
REG_EESCAPE
\
in a\
is invalid, as is the
one in \
.
REG_BADPAT
()
in a()b
is invalid.
REG_ESIZE
REG_ESPACE