man-pages/man3/pcre2_substitute.3.html
2021-03-31 01:06:50 +01:00

119 lines
6.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PCRE2_SUBSTITUTE</TITLE>
</HEAD><BODY>
<H1>PCRE2_SUBSTITUTE</H1>
Section: C Library Functions (3)<BR>Updated: 04 April 2017<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
PCRE2 - Perl-compatible regular expressions (revised API)
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<P>
<B>#include &lt;<A HREF="file:///usr/include/pcre2.h">pcre2.h</A>&gt;</B>
<P>
<PRE>
<B>int pcre2_substitute(const pcre2_code *</B><I>code</I>, PCRE2_SPTR <I>subject</I>,
<B> PCRE2_SIZE </B><I>length</I>, PCRE2_SIZE <I>startoffset</I>,
<B> uint32_t </B><I>options</I>, pcre2_match_data *<I>match_data</I>,
<B> pcre2_match_context *</B><I>mcontext</I>, PCRE2_SPTR <I>replacement</I>,
<B> PCRE2_SIZE </B><I>rlength</I>, PCRE2_UCHAR *<I>outputbuffer</I>,
<B> PCRE2_SIZE *</B><I>outlengthptr</I>);
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
This function matches a compiled regular expression against a given subject
string, using a matching algorithm that is similar to Perl's. It then makes a
copy of the subject, substituting a replacement string for what was matched.
Its arguments are:
<P>
<BR>&nbsp;&nbsp;<I>code</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Points&nbsp;to&nbsp;the&nbsp;compiled&nbsp;pattern
<BR>&nbsp;&nbsp;<I>subject</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Points&nbsp;to&nbsp;the&nbsp;subject&nbsp;string
<BR>&nbsp;&nbsp;<I>length</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Length&nbsp;of&nbsp;the&nbsp;subject&nbsp;string
<BR>&nbsp;&nbsp;<I>startoffset</I>&nbsp;&nbsp;&nbsp;Offset&nbsp;in&nbsp;the&nbsp;subject&nbsp;at&nbsp;which&nbsp;to&nbsp;start&nbsp;matching
<BR>&nbsp;&nbsp;<I>options</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;bits
<BR>&nbsp;&nbsp;<I>match_data</I>&nbsp;&nbsp;&nbsp;&nbsp;Points&nbsp;to&nbsp;a&nbsp;match&nbsp;data&nbsp;block,&nbsp;or&nbsp;is&nbsp;NULL
<BR>&nbsp;&nbsp;<I>mcontext</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Points&nbsp;to&nbsp;a&nbsp;match&nbsp;context,&nbsp;or&nbsp;is&nbsp;NULL
<BR>&nbsp;&nbsp;<I>replacement</I>&nbsp;&nbsp;&nbsp;Points&nbsp;to&nbsp;the&nbsp;replacement&nbsp;string
<BR>&nbsp;&nbsp;<I>rlength</I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Length&nbsp;of&nbsp;the&nbsp;replacement&nbsp;string
<BR>&nbsp;&nbsp;<I>outputbuffer</I>&nbsp;&nbsp;Points&nbsp;to&nbsp;the&nbsp;output&nbsp;buffer
<BR>&nbsp;&nbsp;<I>outlengthptr</I>&nbsp;&nbsp;Points&nbsp;to&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;output&nbsp;buffer
<P>
A match data block is needed only if you want to inspect the data from the
match that is returned in that block. A match context is needed only if you
want to:
<P>
<BR>&nbsp;&nbsp;Set&nbsp;up&nbsp;a&nbsp;callout&nbsp;function
<BR>&nbsp;&nbsp;Set&nbsp;a&nbsp;matching&nbsp;offset&nbsp;limit
<BR>&nbsp;&nbsp;Change&nbsp;the&nbsp;backtracking&nbsp;match&nbsp;limit
<BR>&nbsp;&nbsp;Change&nbsp;the&nbsp;backtracking&nbsp;depth&nbsp;limit
<BR>&nbsp;&nbsp;Set&nbsp;custom&nbsp;memory&nbsp;management&nbsp;in&nbsp;the&nbsp;match&nbsp;context
<P>
The <I>length</I>, <I>startoffset</I> and <I>rlength</I> values are code
units, not characters, as is the contents of the variable pointed at by
<I>outlengthptr</I>, which is updated to the actual length of the new string.
The subject and replacement lengths can be given as PCRE2_ZERO_TERMINATED for
zero-terminated strings. The options are:
<P>
<BR>&nbsp;&nbsp;PCRE2_ANCHORED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Match&nbsp;only&nbsp;at&nbsp;the&nbsp;first&nbsp;position
<BR>&nbsp;&nbsp;PCRE2_ENDANCHORED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pattern&nbsp;can&nbsp;match&nbsp;only&nbsp;at&nbsp;end&nbsp;of&nbsp;subject
<BR>&nbsp;&nbsp;PCRE2_NOTBOL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subject&nbsp;is&nbsp;not&nbsp;the&nbsp;beginning&nbsp;of&nbsp;a&nbsp;line
<BR>&nbsp;&nbsp;PCRE2_NOTEOL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subject&nbsp;is&nbsp;not&nbsp;the&nbsp;end&nbsp;of&nbsp;a&nbsp;line
<BR>&nbsp;&nbsp;PCRE2_NOTEMPTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An&nbsp;empty&nbsp;string&nbsp;is&nbsp;not&nbsp;a&nbsp;valid&nbsp;match
<BR>&nbsp;&nbsp;PCRE2_NOTEMPTY_ATSTART&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An&nbsp;empty&nbsp;string&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;the
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subject&nbsp;is&nbsp;not&nbsp;a&nbsp;valid&nbsp;match
<BR>&nbsp;&nbsp;PCRE2_NO_JIT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do&nbsp;not&nbsp;use&nbsp;JIT&nbsp;matching
<BR>&nbsp;&nbsp;PCRE2_NO_UTF_CHECK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Do&nbsp;not&nbsp;check&nbsp;the&nbsp;subject&nbsp;or&nbsp;replacement
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;UTF&nbsp;validity&nbsp;(only&nbsp;relevant&nbsp;if
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PCRE2_UTF&nbsp;was&nbsp;set&nbsp;at&nbsp;compile&nbsp;time)
<BR>&nbsp;&nbsp;PCRE2_SUBSTITUTE_EXTENDED&nbsp;&nbsp;Do&nbsp;extended&nbsp;replacement&nbsp;processing
<BR>&nbsp;&nbsp;PCRE2_SUBSTITUTE_GLOBAL&nbsp;&nbsp;&nbsp;&nbsp;Replace&nbsp;all&nbsp;occurrences&nbsp;in&nbsp;the&nbsp;subject
<BR>&nbsp;&nbsp;PCRE2_SUBSTITUTE_OVERFLOW_LENGTH&nbsp;&nbsp;If&nbsp;overflow,&nbsp;compute&nbsp;needed&nbsp;length
<BR>&nbsp;&nbsp;PCRE2_SUBSTITUTE_UNKNOWN_UNSET&nbsp;&nbsp;Treat&nbsp;unknown&nbsp;group&nbsp;as&nbsp;unset
<BR>&nbsp;&nbsp;PCRE2_SUBSTITUTE_UNSET_EMPTY&nbsp;&nbsp;Simple&nbsp;unset&nbsp;insert&nbsp;=&nbsp;empty&nbsp;string
<P>
The function returns the number of substitutions, which may be zero if there
were no matches. The result can be greater than one only when
PCRE2_SUBSTITUTE_GLOBAL is set. In the event of an error, a negative error code
is returned.
<P>
There is a complete description of the PCRE2 native API in the
<B>pcre2api</B>
page and a description of the POSIX API in the
<B>pcre2posix</B>
page.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:51 GMT, March 31, 2021
</BODY>
</HTML>