1PCRE2_SUBSTITUTE(3)        Library Functions Manual        PCRE2_SUBSTITUTE(3)
2
3
4

NAME

6       PCRE2 - Perl-compatible regular expressions (revised API)
7

SYNOPSIS

9
10       #include <pcre2.h>
11
12       int pcre2_substitute(const pcre2_code *code, PCRE2_SPTR subject,
13         PCRE2_SIZE length, PCRE2_SIZE startoffset,
14         uint32_t options, pcre2_match_data *match_data,
15         pcre2_match_context *mcontext, PCRE2_SPTR replacement,
16         PCRE2_SIZE rlength, PCRE2_UCHAR *outputbuffer,
17         PCRE2_SIZE *outlengthptr);
18

DESCRIPTION

20
21       This  function  matches  a  compiled regular expression against a given
22       subject string, using a matching algorithm that is similar  to  Perl's.
23       It  then makes a copy of the subject, substituting a replacement string
24       for what was matched.  Its arguments are:
25
26         code          Points to the compiled pattern
27         subject       Points to the subject string
28         length        Length of the subject string
29         startoffset   Offset in the subject at which to start matching
30         options       Option bits
31         match_data    Points to a match data block, or is NULL
32         mcontext      Points to a match context, or is NULL
33         replacement   Points to the replacement string
34         rlength       Length of the replacement string
35         outputbuffer  Points to the output buffer
36         outlengthptr  Points to the length of the output buffer
37
38       A match data block is needed only if you want to inspect the data  from
39       the  final  match  that  is  returned in that block or if PCRE2_SUBSTI‐
40       TUTE_MATCHED is set. A match context is needed only if you want to:
41
42         Set up a callout function
43         Set a matching offset limit
44         Change the backtracking match limit
45         Change the backtracking depth limit
46         Set custom memory management in the match context
47
48       The length, startoffset and rlength values are code units, not  charac‐
49       ters,  as  is  the contents of the variable pointed at by outlengthptr.
50       This variable must contain the length of the  output  buffer  when  the
51       function is called. If the function is successful, the value is changed
52       to the length of the new string, excluding the trailing  zero  that  is
53       automatically added.
54
55       The  subject  and replacement lengths can be given as PCRE2_ZERO_TERMI‐
56       NATED for zero-terminated strings. The options are:
57
58         PCRE2_ANCHORED                     Match only at the first position
59         PCRE2_ENDANCHORED                  Match only at end of subject
60         PCRE2_NOTBOL                       Subject is not the beginning of a
61                                             line
62         PCRE2_NOTEOL                       Subject is not the end of a line
63         PCRE2_NOTEMPTY                     An empty string is not a
64                                             valid match
65         PCRE2_NOTEMPTY_ATSTART             An empty string at the start of
66                                             the subject is not a valid match
67         PCRE2_NO_JIT                       Do not use JIT matching
68         PCRE2_NO_UTF_CHECK                 Do not check for UTF validity in
69                                             the subject or replacement
70                                             (only relevant if PCRE2_UTF was
71                                             set at compile time)
72         PCRE2_SUBSTITUTE_EXTENDED          Do extended replacement processing
73         PCRE2_SUBSTITUTE_GLOBAL            Replace all occurrences in the
74                                             subject
75         PCRE2_SUBSTITUTE_LITERAL           The replacement string is literal
76         PCRE2_SUBSTITUTE_MATCHED           Use pre-existing match data for
77                                             first match
78         PCRE2_SUBSTITUTE_OVERFLOW_LENGTH   If overflow, compute needed length
79         PCRE2_SUBSTITUTE_REPLACEMENT_ONLY  Return only replacement string(s)
80         PCRE2_SUBSTITUTE_UNKNOWN_UNSET     Treat unknown group as unset
81         PCRE2_SUBSTITUTE_UNSET_EMPTY       Simple unset insert = empty string
82
83       If   PCRE2_SUBSTITUTE_LITERAL   is   set,    PCRE2_SUBSTITUTE_EXTENDED,
84       PCRE2_SUBSTITUTE_UNKNOWN_UNSET,  and  PCRE2_SUBSTITUTE_UNSET_EMPTY  are
85       ignored.
86
87       If PCRE2_SUBSTITUTE_MATCHED is set, match_data must  be  non-NULL;  its
88       contents  must  be the result of a call to pcre2_match() using the same
89       pattern and subject.
90
91       The function returns the number of substitutions, which may be zero  if
92       there  are  no  matches.  The  result may be greater than one only when
93       PCRE2_SUBSTITUTE_GLOBAL is set. In the event of an  error,  a  negative
94       error code is returned.
95
96       There is a complete description of the PCRE2 native API in the pcre2api
97       page and a description of the POSIX API in the pcre2posix page.
98
99
100
101PCRE2 10.35                     22 January 2020            PCRE2_SUBSTITUTE(3)
Impressum