tuple_regexp_replace
— Replace a substring using regular expressions.
tuple_regexp_replace( : : Data, Expression, Replace : Result)
tuple_regexp_replace
applies the regular expression in
Expression
to one or more input strings in Data
,
and replaces the first matching substring using the Replace
expression. For each input string, a processed output string is
returned in Result
.
Please refer to the documentation of tuple_regexp_match
for syntax
and options of regular expressions. Additionally, tuple_regexp_replace
supports the option 'replace_all' , which causes all matches
within each individual string to be replaced.
The Replace
expression may use the tag
'$0' to refer to the matched substring in the
input data, '$i' to refer to the submatch of the
i-th capturing group (for i <= 9), and '$$' to
refer to the '$' literal.
For general information about string operations see Tuple / String Operations.
If Data
is an empty tuple, the operator returns an empty tuple. If
Replace
is an empty tuple and Data
is not empty, an
exception is raised.
Regular expression matching operates on Unicode code points. One Unicode
code point may be composed of multiple bytes in the UTF-8 string.
If regular expression matching should only match on bytes, this operator can
be switched to byte mode with
set_system('tsp_tuple_string_operator_mode', 'byte')
. If
'filename_encoding' is set to 'locale' (legacy), this
operator always uses the byte mode.
HDevelop provides an in-line operation for tuple_regexp_replace
,
which can be used in an expression in the following syntax:
Result := regexp_replace(Data, Expression, Replace)
Data
(input_control) string(-array) →
(string)
Input strings to process.
Expression
(input_control) string(-array) →
(string)
Regular expression.
Default value: '.*'
Suggested values: '.*' , 'replace_all' , 'ignore_case' , 'multiline' , 'dot_matches_all' , 'newline_lf' , 'newline_crlf' , 'newline_cr'
Replace
(input_control) string →
(string)
Replacement expression.
Result
(output_control) string(-array) →
(string)
Processed strings.
tuple_regexp_replace(['img10.bmp','img11.bmp','img12.bmp'], \ 'img(.*).bmp', 'out$1.txt', Result) * Returns ['out10.txt','out11.txt','out12.txt']
tuple_regexp_match
,
tuple_regexp_test
,
tuple_regexp_select
Foundation