xref: /aosp_15_r20/external/pcre/doc/html/pcre2_compile.html (revision 22dc650d8ae982c6770746019a6f94af92b0f024)
1*22dc650dSSadaf Ebrahimi<html>
2*22dc650dSSadaf Ebrahimi<head>
3*22dc650dSSadaf Ebrahimi<title>pcre2_compile specification</title>
4*22dc650dSSadaf Ebrahimi</head>
5*22dc650dSSadaf Ebrahimi<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6*22dc650dSSadaf Ebrahimi<h1>pcre2_compile man page</h1>
7*22dc650dSSadaf Ebrahimi<p>
8*22dc650dSSadaf EbrahimiReturn to the <a href="index.html">PCRE2 index page</a>.
9*22dc650dSSadaf Ebrahimi</p>
10*22dc650dSSadaf Ebrahimi<p>
11*22dc650dSSadaf EbrahimiThis page is part of the PCRE2 HTML documentation. It was generated
12*22dc650dSSadaf Ebrahimiautomatically from the original man page. If there is any nonsense in it,
13*22dc650dSSadaf Ebrahimiplease consult the man page, in case the conversion went wrong.
14*22dc650dSSadaf Ebrahimi<br>
15*22dc650dSSadaf Ebrahimi<br><b>
16*22dc650dSSadaf EbrahimiSYNOPSIS
17*22dc650dSSadaf Ebrahimi</b><br>
18*22dc650dSSadaf Ebrahimi<P>
19*22dc650dSSadaf Ebrahimi<b>#include &#60;pcre2.h&#62;</b>
20*22dc650dSSadaf Ebrahimi</P>
21*22dc650dSSadaf Ebrahimi<P>
22*22dc650dSSadaf Ebrahimi<b>pcre2_code *pcre2_compile(PCRE2_SPTR <i>pattern</i>, PCRE2_SIZE <i>length</i>,</b>
23*22dc650dSSadaf Ebrahimi<b>  uint32_t <i>options</i>, int *<i>errorcode</i>, PCRE2_SIZE *<i>erroroffset,</i></b>
24*22dc650dSSadaf Ebrahimi<b>  pcre2_compile_context *<i>ccontext</i>);</b>
25*22dc650dSSadaf Ebrahimi</P>
26*22dc650dSSadaf Ebrahimi<br><b>
27*22dc650dSSadaf EbrahimiDESCRIPTION
28*22dc650dSSadaf Ebrahimi</b><br>
29*22dc650dSSadaf Ebrahimi<P>
30*22dc650dSSadaf EbrahimiThis function compiles a regular expression pattern into an internal form. Its
31*22dc650dSSadaf Ebrahimiarguments are:
32*22dc650dSSadaf Ebrahimi<pre>
33*22dc650dSSadaf Ebrahimi  <i>pattern</i>       A string containing expression to be compiled
34*22dc650dSSadaf Ebrahimi  <i>length</i>        The length of the string or PCRE2_ZERO_TERMINATED
35*22dc650dSSadaf Ebrahimi  <i>options</i>       Primary option bits
36*22dc650dSSadaf Ebrahimi  <i>errorcode</i>     Where to put an error code
37*22dc650dSSadaf Ebrahimi  <i>erroffset</i>     Where to put an error offset
38*22dc650dSSadaf Ebrahimi  <i>ccontext</i>      Pointer to a compile context or NULL
39*22dc650dSSadaf Ebrahimi</pre>
40*22dc650dSSadaf EbrahimiThe length of the pattern and any error offset that is returned are in code
41*22dc650dSSadaf Ebrahimiunits, not characters. A NULL pattern with zero length is treated as an empty
42*22dc650dSSadaf Ebrahimistring. A compile context is needed only if you want to provide custom memory
43*22dc650dSSadaf Ebrahimiallocation functions, or to provide an external function for system stack size
44*22dc650dSSadaf Ebrahimichecking (see <b>pcre2_set_compile_recursion_guard()</b>), or to change one or
45*22dc650dSSadaf Ebrahimimore of these parameters:
46*22dc650dSSadaf Ebrahimi<pre>
47*22dc650dSSadaf Ebrahimi  What \R matches (Unicode newlines, or CR, LF, CRLF only);
48*22dc650dSSadaf Ebrahimi  PCRE2's character tables;
49*22dc650dSSadaf Ebrahimi  The newline character sequence;
50*22dc650dSSadaf Ebrahimi  The compile time nested parentheses limit;
51*22dc650dSSadaf Ebrahimi  The maximum pattern length (in code units) that is allowed;
52*22dc650dSSadaf Ebrahimi  The additional options bits.
53*22dc650dSSadaf Ebrahimi</pre>
54*22dc650dSSadaf EbrahimiThe primary option bits are:
55*22dc650dSSadaf Ebrahimi<pre>
56*22dc650dSSadaf Ebrahimi  PCRE2_ANCHORED           Force pattern anchoring
57*22dc650dSSadaf Ebrahimi  PCRE2_ALLOW_EMPTY_CLASS  Allow empty classes
58*22dc650dSSadaf Ebrahimi  PCRE2_ALT_BSUX           Alternative handling of \u, \U, and \x
59*22dc650dSSadaf Ebrahimi  PCRE2_ALT_CIRCUMFLEX     Alternative handling of ^ in multiline mode
60*22dc650dSSadaf Ebrahimi  PCRE2_ALT_VERBNAMES      Process backslashes in verb names
61*22dc650dSSadaf Ebrahimi  PCRE2_AUTO_CALLOUT       Compile automatic callouts
62*22dc650dSSadaf Ebrahimi  PCRE2_CASELESS           Do caseless matching
63*22dc650dSSadaf Ebrahimi  PCRE2_DOLLAR_ENDONLY     $ not to match newline at end
64*22dc650dSSadaf Ebrahimi  PCRE2_DOTALL             . matches anything including NL
65*22dc650dSSadaf Ebrahimi  PCRE2_DUPNAMES           Allow duplicate names for subpatterns
66*22dc650dSSadaf Ebrahimi  PCRE2_ENDANCHORED        Pattern can match only at end of subject
67*22dc650dSSadaf Ebrahimi  PCRE2_EXTENDED           Ignore white space and # comments
68*22dc650dSSadaf Ebrahimi  PCRE2_FIRSTLINE          Force matching to be before newline
69*22dc650dSSadaf Ebrahimi  PCRE2_LITERAL            Pattern characters are all literal
70*22dc650dSSadaf Ebrahimi  PCRE2_MATCH_INVALID_UTF  Enable support for matching invalid UTF
71*22dc650dSSadaf Ebrahimi  PCRE2_MATCH_UNSET_BACKREF  Match unset backreferences
72*22dc650dSSadaf Ebrahimi  PCRE2_MULTILINE          ^ and $ match newlines within data
73*22dc650dSSadaf Ebrahimi  PCRE2_NEVER_BACKSLASH_C  Lock out the use of \C in patterns
74*22dc650dSSadaf Ebrahimi  PCRE2_NEVER_UCP          Lock out PCRE2_UCP, e.g. via (*UCP)
75*22dc650dSSadaf Ebrahimi  PCRE2_NEVER_UTF          Lock out PCRE2_UTF, e.g. via (*UTF)
76*22dc650dSSadaf Ebrahimi  PCRE2_NO_AUTO_CAPTURE    Disable numbered capturing paren-
77*22dc650dSSadaf Ebrahimi                            theses (named ones available)
78*22dc650dSSadaf Ebrahimi  PCRE2_NO_AUTO_POSSESS    Disable auto-possessification
79*22dc650dSSadaf Ebrahimi  PCRE2_NO_DOTSTAR_ANCHOR  Disable automatic anchoring for .*
80*22dc650dSSadaf Ebrahimi  PCRE2_NO_START_OPTIMIZE  Disable match-time start optimizations
81*22dc650dSSadaf Ebrahimi  PCRE2_NO_UTF_CHECK       Do not check the pattern for UTF validity
82*22dc650dSSadaf Ebrahimi                             (only relevant if PCRE2_UTF is set)
83*22dc650dSSadaf Ebrahimi  PCRE2_UCP                Use Unicode properties for \d, \w, etc.
84*22dc650dSSadaf Ebrahimi  PCRE2_UNGREEDY           Invert greediness of quantifiers
85*22dc650dSSadaf Ebrahimi  PCRE2_USE_OFFSET_LIMIT   Enable offset limit for unanchored matching
86*22dc650dSSadaf Ebrahimi  PCRE2_UTF                Treat pattern and subjects as UTF strings
87*22dc650dSSadaf Ebrahimi</pre>
88*22dc650dSSadaf EbrahimiPCRE2 must be built with Unicode support (the default) in order to use
89*22dc650dSSadaf EbrahimiPCRE2_UTF, PCRE2_UCP and related options.
90*22dc650dSSadaf Ebrahimi</P>
91*22dc650dSSadaf Ebrahimi<P>
92*22dc650dSSadaf EbrahimiAdditional options may be set in the compile context via the
93*22dc650dSSadaf Ebrahimi<a href="pcre2_set_compile_extra_options.html"><b>pcre2_set_compile_extra_options</b></a>
94*22dc650dSSadaf Ebrahimifunction.
95*22dc650dSSadaf Ebrahimi</P>
96*22dc650dSSadaf Ebrahimi<P>
97*22dc650dSSadaf EbrahimiIf either of <i>errorcode</i> or <i>erroroffset</i> is NULL, the function returns
98*22dc650dSSadaf EbrahimiNULL immediately. Otherwise, the yield of this function is a pointer to a
99*22dc650dSSadaf Ebrahimiprivate data structure that contains the compiled pattern, or NULL if an error
100*22dc650dSSadaf Ebrahimiwas detected. In the error case, a text error message can be obtained by
101*22dc650dSSadaf Ebrahimipassing the value returned via the <i>errorcode</i> argument to the
102*22dc650dSSadaf Ebrahimi<b>pcre2_get_error_message()</b> function. The offset (in code units) where the
103*22dc650dSSadaf Ebrahimierror was encountered is returned via the <i>erroroffset</i> argument.
104*22dc650dSSadaf Ebrahimi</P>
105*22dc650dSSadaf Ebrahimi<P>
106*22dc650dSSadaf EbrahimiIf there is no error, the value passed via <i>errorcode</i> returns the message
107*22dc650dSSadaf Ebrahimi"no error" if passed to <b>pcre2_get_error_message()</b>, and the value passed
108*22dc650dSSadaf Ebrahimivia <i>erroroffset</i> is zero.
109*22dc650dSSadaf Ebrahimi</P>
110*22dc650dSSadaf Ebrahimi<P>
111*22dc650dSSadaf EbrahimiThere is a complete description of the PCRE2 native API, with more detail on
112*22dc650dSSadaf Ebrahimieach option, in the
113*22dc650dSSadaf Ebrahimi<a href="pcre2api.html"><b>pcre2api</b></a>
114*22dc650dSSadaf Ebrahimipage, and a description of the POSIX API in the
115*22dc650dSSadaf Ebrahimi<a href="pcre2posix.html"><b>pcre2posix</b></a>
116*22dc650dSSadaf Ebrahimipage.
117*22dc650dSSadaf Ebrahimi<p>
118*22dc650dSSadaf EbrahimiReturn to the <a href="index.html">PCRE2 index page</a>.
119*22dc650dSSadaf Ebrahimi</p>
120