regcomp.3c (2010 09)
r
regcomp(3C) regcomp(3C)
NAME
regcomp( ), regerror( ), regexec( ), regfree( ) - regular expression matching routines
SYNOPSIS
#include <regex.h>
int regcomp(regex_t *__restrict preg, const char *__restrict pattern,
int cflags);
int regexec(
const regex_t *__restrict preg,
const char *__restrict string,
size_t nmatch,
regmatch_t pmatch[__restrict],
int eflags
);
void regfree(regex_t *preg);
size_t regerror(
int errcode,
const regex_t *__restrict preg,
char *__restrict errbuf,
size_t errbuf_size
);
DESCRIPTION
These functions interpret regular expressions as described in regexp (5). They support both basic and
extended regular expressions.
The structures
regex_t and regmatch_t are defined in the header <regex.h>.
The
regex_t structure contains at least the following member (use of other members results in non-
portable code):
size_t re_nsub Number of parenthesized subexpressions.
The
regmatch_t structure contains at least the following members:
regoff_t rm_so Byte offset from start of string to start of substring.
regoff_t rm_eo Byte offset from start of string to the first character after the end of the
substring.
regcomp() compiles the regular expression specified by the pattern argument and places the results in
the structure pointed to by preg . The cflags argument is the bit-wise logical OR of zero or more of the fol-
lowing flags (defined in <regex.h>):
REG_EXTENDED Use extended regular expressions.
REG_NEWLINE If REG_NEWLINE is not set in cflags, a newline character in pattern or string is
treated as an ordinary character. If REG_NEWLINE is set, newlines are treated
as ordinary characters except as follows:
1. A newline in string is not matched by a period outside of a bracket expres-
sion or by any form of a nonmatching list.
2. A circumflex (
ˆ)inpattern , when used to specify expression anchoring,
matches the zero-length string immediately after a newline in string ,
regardless of the setting of REG_NOTBOL.
3. A dollar-sign (
$)inpattern , when used to specify expression anchoring,
matches the zero-length string immediately before a newline in string ,
regardless of the setting of REG_NOTEOL.
REG_ICASE Ignore case in match. If a character in pattern is defined in the current
LC_CTYPE locale as having one or more opposite-case counterpoints, both the
character and any counterpoints match the pattern character. This applies to all
portions of the pattern, including a string of characters specified to be matched
via a back-reference expression (\n).
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1