pcre2_substitute.3 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. .TH PCRE2_SUBSTITUTE 3 "22 January 2020" "PCRE2 10.35"
  2. .SH NAME
  3. PCRE2 - Perl-compatible regular expressions (revised API)
  4. .SH SYNOPSIS
  5. .rs
  6. .sp
  7. .B #include <pcre2.h>
  8. .PP
  9. .nf
  10. .B int pcre2_substitute(const pcre2_code *\fIcode\fP, PCRE2_SPTR \fIsubject\fP,
  11. .B " PCRE2_SIZE \fIlength\fP, PCRE2_SIZE \fIstartoffset\fP,"
  12. .B " uint32_t \fIoptions\fP, pcre2_match_data *\fImatch_data\fP,"
  13. .B " pcre2_match_context *\fImcontext\fP, PCRE2_SPTR \fIreplacement\fP,"
  14. .B " PCRE2_SIZE \fIrlength\fP, PCRE2_UCHAR *\fIoutputbuffer\fP,"
  15. .B " PCRE2_SIZE *\fIoutlengthptr\fP);"
  16. .fi
  17. .
  18. .SH DESCRIPTION
  19. .rs
  20. .sp
  21. This function matches a compiled regular expression against a given subject
  22. string, using a matching algorithm that is similar to Perl's. It then makes a
  23. copy of the subject, substituting a replacement string for what was matched.
  24. Its arguments are:
  25. .sp
  26. \fIcode\fP Points to the compiled pattern
  27. \fIsubject\fP Points to the subject string
  28. \fIlength\fP Length of the subject string
  29. \fIstartoffset\fP Offset in the subject at which to start matching
  30. \fIoptions\fP Option bits
  31. \fImatch_data\fP Points to a match data block, or is NULL
  32. \fImcontext\fP Points to a match context, or is NULL
  33. \fIreplacement\fP Points to the replacement string
  34. \fIrlength\fP Length of the replacement string
  35. \fIoutputbuffer\fP Points to the output buffer
  36. \fIoutlengthptr\fP Points to the length of the output buffer
  37. .sp
  38. A match data block is needed only if you want to inspect the data from the
  39. final match that is returned in that block or if PCRE2_SUBSTITUTE_MATCHED is
  40. set. A match context is needed only if you want to:
  41. .sp
  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. .sp
  48. The \fIlength\fP, \fIstartoffset\fP and \fIrlength\fP values are code units,
  49. not characters, as is the contents of the variable pointed at by
  50. \fIoutlengthptr\fP. This variable must contain the length of the output buffer
  51. when the function is called. If the function is successful, the value is
  52. changed to the length of the new string, excluding the trailing zero that is
  53. automatically added.
  54. .P
  55. The subject and replacement lengths can be given as PCRE2_ZERO_TERMINATED for
  56. zero-terminated strings. The options are:
  57. .sp
  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. .\" JOIN
  64. PCRE2_NOTEMPTY_ATSTART An empty string at the start of the
  65. subject is not a valid match
  66. PCRE2_NO_JIT Do not use JIT matching
  67. .\" JOIN
  68. PCRE2_NO_UTF_CHECK Do not check the subject or replacement
  69. for UTF validity (only relevant if
  70. PCRE2_UTF was set at compile time)
  71. PCRE2_SUBSTITUTE_EXTENDED Do extended replacement processing
  72. PCRE2_SUBSTITUTE_GLOBAL Replace all occurrences in the subject
  73. PCRE2_SUBSTITUTE_LITERAL The replacement string is literal
  74. PCRE2_SUBSTITUTE_MATCHED Use pre-existing match data for 1st match
  75. PCRE2_SUBSTITUTE_OVERFLOW_LENGTH If overflow, compute needed length
  76. PCRE2_SUBSTITUTE_REPLACEMENT_ONLY Return only replacement string(s)
  77. PCRE2_SUBSTITUTE_UNKNOWN_UNSET Treat unknown group as unset
  78. PCRE2_SUBSTITUTE_UNSET_EMPTY Simple unset insert = empty string
  79. .sp
  80. If PCRE2_SUBSTITUTE_LITERAL is set, PCRE2_SUBSTITUTE_EXTENDED,
  81. PCRE2_SUBSTITUTE_UNKNOWN_UNSET, and PCRE2_SUBSTITUTE_UNSET_EMPTY are ignored.
  82. .P
  83. If PCRE2_SUBSTITUTE_MATCHED is set, \fImatch_data\fP must be non-zero; its
  84. contents must be the result of a call to \fBpcre2_match()\fP using the same
  85. pattern and subject.
  86. .P
  87. The function returns the number of substitutions, which may be zero if there
  88. are no matches. The result may be greater than one only when
  89. PCRE2_SUBSTITUTE_GLOBAL is set. In the event of an error, a negative error code
  90. is returned.
  91. .P
  92. There is a complete description of the PCRE2 native API in the
  93. .\" HREF
  94. \fBpcre2api\fP
  95. .\"
  96. page and a description of the POSIX API in the
  97. .\" HREF
  98. \fBpcre2posix\fP
  99. .\"
  100. page.