HPlogo MPE/iX Developer's Kit Reference Manual Volume I: HP 3000 MPE/iX Computer Systems > Chapter 4  POSIX/iX Library Function Descriptions

regcomp

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Compile a regular expression.

Syntax

   #include <regex.h>

   int regcomp (regex_t *reg, const char *regstr, int flags);

Parameters

reg

points to an object where regcomp() stores the compiled regular expression. regex_t is defined in <regex.h>.

regstr

points to the regular expression as a string (the way it might be specified for a command like grep).

flags

gives a variety of flags for the compilation. Flags are given by symbols defined in <regex.h> which can be ORed together. The recognized symbols are:

REG_EXTENDED

uses extended regular expressions (see regexp(3)). The default is to interpret regstr as a basic regular expression.

REG_ICASE

ignores the case of letters in matches. The setting of LC_CTYPE affects which characters are considered to be opposite cases of each other.

REG_NEWLINE

treats the newline character as a regular character, without its special meaning.

REG_NOSUB

indicates that regcomp() should only report success or failure, and not set reg->re_nsub (see the following section). It also affects the behavior of regexec(3)

Return Values

0

Successful compile

Error code

Not successful compile

Description

regcomp() compiles a regular expression for later use. Early implementations of regcomp() generated executable code that determined whether or not strings matched regstr. Under POSIX.2, regcomp() may generate executable code and/or data which speeds pattern-matching. The result of regcomp() is a structure of the regex_t type which is stored in reg. This structure type contains at least the following field:

size_t re_nsub

is usually set to the number of parenthesized subexpressions found in regstr. These subexpressions are delimited with

   \(\)

in basic regular expressions and

   ()

in extended regular expressions. regcomp() does not set re_nsub if REG_NOSUB is turned on in flags.

Errors

If regcomp() successfully compiles regstr it returns zero; otherwise, it returns one of the following symbolic values:

REG_BADBRCAUSE

The contents of

   \{\}

were invalid: not a number, too large a number, more than two numbers, first number larger than second.

 ACTIONMake sure that the contents of \{\} or {} are valid.
REG_BADPATCAUSEregstr was an invalid regular expression.
 ACTIONSpecify a valid regular expression
REG_BADRPTCAUSEregstr contained a ?, *, or + that was not preceded by a valid regular expression.
 ACTIONMake sure that every unquoted /, *, or + in regstr is preceded by a valid regular expression.
REG_EBRACECAUSEregstr contained a \{\} imbalance.
 ACTIONMake sure that all { and } characters and all \{ and \} characters appear in matched pairs in regstr.
REG_EBRACKCAUSEregstr contained a [] imbalance.
 ACTIONMake sure that all [ and ] characters appear in matched pairs in regstr.
REG_ECOLLATECAUSEregstr contained a reference to an invalid collating element.
 ACTIONMake sure that all collating elements referenced in regstr are valid in the locale indicated by LC_COLLATE.
REG_ECTYPECAUSEregstr contained a reference to an invalid character class.
 ACTIONMake sure that all character classes referenced in regstr are valid in the locale indicated by LC_CTYPE.
REG_EESCAPECAUSEregstr contained a trailing \.
 ACTIONRemove the trailing \ or complete the escape sequence.
REG_ENEWLINECAUSEA newline was found before the end of a pattern, and the REG_ENEWLINE flag was not set.
 ACTIONSet the REG_ENEWLINE flag, or check the pattern for a missing /.
REG_EPARENCAUSEregstr contained a () or \(\) imbalance.
 ACTIONMake sure that all ( and ) characters and all \( and \) characters appear in matched pairs in regstr.
REG_ERANGECAUSEA range expression contained an invalid endpoint. For example, an equivalence or character class is not valid.
 ACTIONSpecify a valid endpoint.
REG_ESPACECAUSEThere were not enough free system resources for regcomp() to compile regstr
 ACTIONFree up more resources or specify a less complex regular expression.
REG_ESUBREGCAUSEThe number in a \number construct was greater than the number of matching subexpressions.
 ACTIONMake sure that number is less than or equal to the number of matching subexpressions.
REG_EFATALCAUSEAn internal error occurred.
 ACTIONContact your system manager.

See Also

grep(1), regexec(), regfree(), regexp(3)

Feedback to webmaster