www.delorie.com/gnu/docs/regex/regex_56.html   search  
Buy the book!


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2.2 POSIX Regular Expression Compiling

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:

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':

says to use POSIX Extended Regular Expression syntax; if this isn't set, then says to use POSIX Basic Regular Expression syntax. regcomp sets preg's syntax field accordingly.

says to ignore case; regcomp sets preg's translate field to a translate table which ignores case, replacing anything you've put there before.

says to set preg's no_sub field; see section 7.2.3 POSIX Matching, for what this means.

says that a:

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 7.1.2 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.)

For example, the consecutive repetition operators `**' 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.

For example, the count `-1' in `a\{-1' is invalid.

For example, `a\{1' is missing a close-interval operator.

For example, `[a' is missing a close-list operator.

For example, the range ending point `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:]-|]'.

For example, the character class name `foo' in `[[:foo:]' is invalid.

For example, `a\)' is missing an open-group operator and `\(a' is missing a close-group operator.

For example, the back reference `\2' that refers to a nonexistent subexpression in `\(a\)\2' is invalid.

Returned when a regular expression causes no other more specific error.

For example, the trailing backslash `\' in `a\' is invalid, as is the one in `\'.

For example, in the extended regular expression syntax, the empty group `()' in `a()b' is invalid.

Returned when a regular expression needs a pattern buffer larger than 65536 bytes.

Returned when a regular expression makes Regex to run out of memory.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003