1*22dc650dSSadaf Ebrahimi<html> 2*22dc650dSSadaf Ebrahimi<head> 3*22dc650dSSadaf Ebrahimi<title>pcre2_substitute 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_substitute 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 <pcre2.h></b> 20*22dc650dSSadaf Ebrahimi</P> 21*22dc650dSSadaf Ebrahimi<P> 22*22dc650dSSadaf Ebrahimi<b>int pcre2_substitute(const pcre2_code *<i>code</i>, PCRE2_SPTR <i>subject</i>,</b> 23*22dc650dSSadaf Ebrahimi<b> PCRE2_SIZE <i>length</i>, PCRE2_SIZE <i>startoffset</i>,</b> 24*22dc650dSSadaf Ebrahimi<b> uint32_t <i>options</i>, pcre2_match_data *<i>match_data</i>,</b> 25*22dc650dSSadaf Ebrahimi<b> pcre2_match_context *<i>mcontext</i>, PCRE2_SPTR <i>replacement</i>,</b> 26*22dc650dSSadaf Ebrahimi<b> PCRE2_SIZE <i>rlength</i>, PCRE2_UCHAR *<i>outputbuffer</i>,</b> 27*22dc650dSSadaf Ebrahimi<b> PCRE2_SIZE *<i>outlengthptr</i>);</b> 28*22dc650dSSadaf Ebrahimi</P> 29*22dc650dSSadaf Ebrahimi<br><b> 30*22dc650dSSadaf EbrahimiDESCRIPTION 31*22dc650dSSadaf Ebrahimi</b><br> 32*22dc650dSSadaf Ebrahimi<P> 33*22dc650dSSadaf EbrahimiThis function matches a compiled regular expression against a given subject 34*22dc650dSSadaf Ebrahimistring, using a matching algorithm that is similar to Perl's. It then makes a 35*22dc650dSSadaf Ebrahimicopy of the subject, substituting a replacement string for what was matched. 36*22dc650dSSadaf EbrahimiIts arguments are: 37*22dc650dSSadaf Ebrahimi<pre> 38*22dc650dSSadaf Ebrahimi <i>code</i> Points to the compiled pattern 39*22dc650dSSadaf Ebrahimi <i>subject</i> Points to the subject string 40*22dc650dSSadaf Ebrahimi <i>length</i> Length of the subject string 41*22dc650dSSadaf Ebrahimi <i>startoffset</i> Offset in the subject at which to start matching 42*22dc650dSSadaf Ebrahimi <i>options</i> Option bits 43*22dc650dSSadaf Ebrahimi <i>match_data</i> Points to a match data block, or is NULL 44*22dc650dSSadaf Ebrahimi <i>mcontext</i> Points to a match context, or is NULL 45*22dc650dSSadaf Ebrahimi <i>replacement</i> Points to the replacement string 46*22dc650dSSadaf Ebrahimi <i>rlength</i> Length of the replacement string 47*22dc650dSSadaf Ebrahimi <i>outputbuffer</i> Points to the output buffer 48*22dc650dSSadaf Ebrahimi <i>outlengthptr</i> Points to the length of the output buffer 49*22dc650dSSadaf Ebrahimi</pre> 50*22dc650dSSadaf EbrahimiA match data block is needed only if you want to inspect the data from the 51*22dc650dSSadaf Ebrahimifinal match that is returned in that block or if PCRE2_SUBSTITUTE_MATCHED is 52*22dc650dSSadaf Ebrahimiset. A match context is needed only if you want to: 53*22dc650dSSadaf Ebrahimi<pre> 54*22dc650dSSadaf Ebrahimi Set up a callout function 55*22dc650dSSadaf Ebrahimi Set a matching offset limit 56*22dc650dSSadaf Ebrahimi Change the backtracking match limit 57*22dc650dSSadaf Ebrahimi Change the backtracking depth limit 58*22dc650dSSadaf Ebrahimi Set custom memory management in the match context 59*22dc650dSSadaf Ebrahimi</pre> 60*22dc650dSSadaf EbrahimiThe <i>length</i>, <i>startoffset</i> and <i>rlength</i> values are code units, 61*22dc650dSSadaf Ebrahiminot characters, as is the contents of the variable pointed at by 62*22dc650dSSadaf Ebrahimi<i>outlengthptr</i>. This variable must contain the length of the output buffer 63*22dc650dSSadaf Ebrahimiwhen the function is called. If the function is successful, the value is 64*22dc650dSSadaf Ebrahimichanged to the length of the new string, excluding the trailing zero that is 65*22dc650dSSadaf Ebrahimiautomatically added. 66*22dc650dSSadaf Ebrahimi</P> 67*22dc650dSSadaf Ebrahimi<P> 68*22dc650dSSadaf EbrahimiThe subject and replacement lengths can be given as PCRE2_ZERO_TERMINATED for 69*22dc650dSSadaf Ebrahimizero-terminated strings. The options are: 70*22dc650dSSadaf Ebrahimi<pre> 71*22dc650dSSadaf Ebrahimi PCRE2_ANCHORED Match only at the first position 72*22dc650dSSadaf Ebrahimi PCRE2_ENDANCHORED Match only at end of subject 73*22dc650dSSadaf Ebrahimi PCRE2_NOTBOL Subject is not the beginning of a line 74*22dc650dSSadaf Ebrahimi PCRE2_NOTEOL Subject is not the end of a line 75*22dc650dSSadaf Ebrahimi PCRE2_NOTEMPTY An empty string is not a valid match 76*22dc650dSSadaf Ebrahimi PCRE2_NOTEMPTY_ATSTART An empty string at the start of the subject is not a valid match 77*22dc650dSSadaf Ebrahimi PCRE2_NO_JIT Do not use JIT matching 78*22dc650dSSadaf Ebrahimi PCRE2_NO_UTF_CHECK Do not check for UTF validity in the subject or replacement 79*22dc650dSSadaf Ebrahimi (only relevant if PCRE2_UTF was set at compile time) 80*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_EXTENDED Do extended replacement processing 81*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_GLOBAL Replace all occurrences in the subject 82*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_LITERAL The replacement string is literal 83*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_MATCHED Use pre-existing match data for first match 84*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_OVERFLOW_LENGTH If overflow, compute needed length 85*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_REPLACEMENT_ONLY Return only replacement string(s) 86*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_UNKNOWN_UNSET Treat unknown group as unset 87*22dc650dSSadaf Ebrahimi PCRE2_SUBSTITUTE_UNSET_EMPTY Simple unset insert = empty string 88*22dc650dSSadaf Ebrahimi</pre> 89*22dc650dSSadaf EbrahimiIf PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_EXTENDED, 90*22dc650dSSadaf EbrahimiPCRE2_SUBSTITUTE_UNKNOWN_UNSET, and PCRE2_SUBSTITUTE_UNSET_EMPTY are ignored. 91*22dc650dSSadaf Ebrahimi</P> 92*22dc650dSSadaf Ebrahimi<P> 93*22dc650dSSadaf EbrahimiIf PCRE2_SUBSTITUTE_MATCHED is set, <i>match_data</i> must be non-NULL; its 94*22dc650dSSadaf Ebrahimicontents must be the result of a call to <b>pcre2_match()</b> using the same 95*22dc650dSSadaf Ebrahimipattern and subject. 96*22dc650dSSadaf Ebrahimi</P> 97*22dc650dSSadaf Ebrahimi<P> 98*22dc650dSSadaf EbrahimiThe function returns the number of substitutions, which may be zero if there 99*22dc650dSSadaf Ebrahimiare no matches. The result may be greater than one only when 100*22dc650dSSadaf EbrahimiPCRE2_SUBSTITUTE_GLOBAL is set. In the event of an error, a negative error code 101*22dc650dSSadaf Ebrahimiis returned. 102*22dc650dSSadaf Ebrahimi</P> 103*22dc650dSSadaf Ebrahimi<P> 104*22dc650dSSadaf EbrahimiThere is a complete description of the PCRE2 native API in the 105*22dc650dSSadaf Ebrahimi<a href="pcre2api.html"><b>pcre2api</b></a> 106*22dc650dSSadaf Ebrahimipage and a description of the POSIX API in the 107*22dc650dSSadaf Ebrahimi<a href="pcre2posix.html"><b>pcre2posix</b></a> 108*22dc650dSSadaf Ebrahimipage. 109*22dc650dSSadaf Ebrahimi<p> 110*22dc650dSSadaf EbrahimiReturn to the <a href="index.html">PCRE2 index page</a>. 111*22dc650dSSadaf Ebrahimi</p> 112