regcomp()

compile regular expression 

Function


SYNOPSIS

#include <sys/types.h>

#include <regex.h>

int regcomp(regex_t *preg, const char *pattern, int cflags);


DESCRIPTION

The regcomp() function compiles the regular expression contained in the string pointed to by the pattern argument and place the results in the structure pointed to by preg. The cflags argument is the bitwise inclusive OR of zero or more of the following flags, which are defined in the header <regex.h>:

REG_EXTENDED 

Use extended regular expressions.

REG_ICASE 

Ignore case in match.

REG_NOSUB 

Report only success or failure in regexec().

REG_NEWLINE 

Change the handling of newline characters, as described in the text.

The default regular expression type for pattern is a basic regular expression. The application can specify extended regular expressions using the REG_EXTENDED cflags flag.

The following structure types contain at least the following members:

Structure Type Member Type Member Name Description
regex_t size_t re_nsub Number of parenthesized subexpressions

If the REG_NOSUB flag was not set in cflags, regcomp() sets re_nsub to the number of parenthesized subexpressions (delimited by \( \) in basic regular expressions or () in extended regular expressions) found in pattern.

The regfree() function frees any memory allocated by regcomp() associated with preg.


PARAMETERS

preg 

Points to the structure where the results are placed.

pattern 

Points to the string that the regular expression.

cflags 

The bitwise inclusive OR of zero or more of the flags defined in the header <regex.h>.


RETURN VALUES

On successful completion, the regcomp() function returns 0. Otherwise, it returns an integer value indicating an error as below, and the content of preg is undefined.

REG_BADPAT 

A regular expression was invalid.

REG_ECOLLATE 

An invalid collating element was referenced.

REG_ECTYPE 

An invalid character class type was referenced.

REG_EESCAPE 

A trailing \ was in the pattern.

REG_ESUBREG 

A number in \digit was invalid or in error.

REG_EBRACK 

A [ ] imbalance exists

REG_ENOSYS 

The function is not supported.

REG_EPAREN 

A \( \) or ( ) imbalance exists.

REG_EBRACE 

A \{ \} imbalance exists.

REG_BADBR 

The contents of \{ \} are invalid: not a number, number too large, more than two numbers, first larger than second.

REG_ERANGE 

An endpoint in a range expression is invalid.

REG_ESPACE 

Out of memory.

REG_BADRPT 

?, * or + is not preceded by valid regular expression.


CONFORMANCE

POSIX.2 (1992).


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
fnmatch(), glob(), regerror(), regexec(), regfree()


PTC MKS Toolkit 9.6 Documentation Build 9.