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          Pattern can match only at end of subject
60         PCRE2_NOTBOL               Subject is not the beginning of a line
61         PCRE2_NOTEOL               Subject is not the end of a line
62         PCRE2_NOTEMPTY             An empty string is not a valid match
63         PCRE2_NOTEMPTY_ATSTART     An empty string at the start of the
64                                     subject is not a valid match
65         PCRE2_NO_JIT               Do not use JIT matching
66         PCRE2_NO_UTF_CHECK         Do not check the subject or replacement
67                                     for UTF validity (only relevant if
68                                     PCRE2_UTF was set at compile time)
69         PCRE2_SUBSTITUTE_EXTENDED  Do extended replacement processing
70         PCRE2_SUBSTITUTE_GLOBAL    Replace all occurrences in the subject
71         PCRE2_SUBSTITUTE_LITERAL   The replacement string is literal
72         PCRE2_SUBSTITUTE_MATCHED   Use pre-existing match data for 1st match
73         PCRE2_SUBSTITUTE_OVERFLOW_LENGTH  If overflow, compute needed length
74         PCRE2_SUBSTITUTE_REPLACEMENT_ONLY  Return only replacement string(s)
75         PCRE2_SUBSTITUTE_UNKNOWN_UNSET  Treat unknown group as unset
76         PCRE2_SUBSTITUTE_UNSET_EMPTY  Simple unset insert = empty string
77
78       If   PCRE2_SUBSTITUTE_LITERAL   is   set,    PCRE2_SUBSTITUTE_EXTENDED,
79       PCRE2_SUBSTITUTE_UNKNOWN_UNSET,  and  PCRE2_SUBSTITUTE_UNSET_EMPTY  are
80       ignored.
81
82       If PCRE2_SUBSTITUTE_MATCHED is set, match_data must  be  non-zero;  its
83       contents  must  be the result of a call to pcre2_match() using the same
84       pattern and subject.
85
86       The function returns the number of substitutions, which may be zero  if
87       there  are  no  matches.  The  result may be greater than one only when
88       PCRE2_SUBSTITUTE_GLOBAL is set. In the event of an  error,  a  negative
89       error code is returned.
90
91       There is a complete description of the PCRE2 native API in the pcre2api
92       page and a description of the POSIX API in the pcre2posix page.
93
94
95
96PCRE2 10.35                     22 January 2020            PCRE2_SUBSTITUTE(3)
Impressum