HP-UX Reference (11i v2 07/12) - 3 Library Functions N-Z (vol 7)

r
regcomp(3C) regcomp(3C)
If the preg argument to regexec() or
regfree() is not a compiled regular expression returned by
regcomp(), the result is undefined. A preg can no longer be treated as a compiled regular expression
after it is given to
regfree().
regerror() provides a mapping from error codes returned by
regcomp() and regexec() to print-
able strings.
regerror() generates a string corresponding to the value of the errcode parameter,
which was the last non-zero value returned by
regcomp() or regexec() with the given value of preg.
The errcode parameter can take on any of the error values defined in <
regex.h>. If errbuf_size is not
zero,
regerror() copies an appropriate error message into the buffer specified by errbuf. If the error
message (including the terminating null) cannot fit in the buffer, it is truncated to errbuf_size 1 bytes and
null terminated.
If errbuf_size is zero, the errbuf parameter is ignored, but the return value is as defined below.
regerror() returns the size of the buffer (including terminating null) that is required to hold the entire
error message.
EXTERNAL INFLUENCES
Locale
The LC_COLLATE category determines the collating sequence used in compiling and executing regular
expressions.
The LC_CTYPE category determines the interpretation of text as single and/or multi-byte characters, the
characters matched by character-class expressions in regular expressions, and the opposite-case counter-
part for each character.
International Code Set Support
Single- and multi-byte character code sets are supported. However, if the LC_COLLATE and LC_CTYPE
variables specify locale categories that are not based upon the same underlying codeset, the results of
regcomp() is undefined.
RETURN VALUE
regcomp() returns zero for success and non-zero for an invalid expression or other failure.
regexec() returns zero if it finds a match and non-zero for no match or other failure.
ERRORS
If regcomp() or regexec() detects one of the error conditions listed below, it returns the correspond-
ing non-zero error code. The error codes are defined in the header <regex.h
>.
REG_BADBR The contents within the pair \{ (backslash left brace) and \} (backslash right
brace) are unusable: not a number, number too large, more than two numbers,
or first number larger than second.
REG_BADPAT An invalid regular expression.
REG_BADRPT The ? (question mark), * (asterisk), or + (plus sign) symbols are not preceded
by a valid regular expression.
REG_EBRACE The use of a pair of \{ (backslash left brace) and \} (backslash right brace) or
{} (braces) is unbalanced.
REG_EBRACK The use of [] (brackets) is unbalanced.
REG_EBOL Using the ˆ (caret) anchor and not beginning of line.
REG_ECHAR There is an invalid multibyte character.
REG_ECOLLATE There is an unusable collating element referenced.
REG_ECTYPE There is an unusable character class type referenced.
REG_EEOL Using the $ (dollar) anchor and not end of line.
REG_EESCAPE There is a trailing \ in the pattern.
REG_EPAREN The use of a pair of \( (backslash left parenthesis) and \) (backslash right
parenthesis) or () is unbalanced.
REG_ERANGE There is an unusable endpoint in the range expression.
302 Hewlett-Packard Company 3 HP-UX 11i Version 2: December 2007 Update