tuple_regexp_replacetuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replace (算子)
名称
tuple_regexp_replacetuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replace — 使用正则表达式替换子字符串。
签名
def tuple_regexp_replace(data: MaybeSequence[str], expression: MaybeSequence[str], replace: str) -> Sequence[str]
def tuple_regexp_replace_s(data: MaybeSequence[str], expression: MaybeSequence[str], replace: str) -> str
描述
tuple_regexp_replacetuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replace applies the regular expression in
ExpressionExpressionExpressionExpressionexpressionexpression to one or more input strings in DataDataDataDatadatadata,
and replaces the first matching substring using the ReplaceReplaceReplaceReplacereplacereplace
expression. For each input string, a processed output string is
returned in ResultResultResultResultresultresult。
Please refer to the documentation of tuple_regexp_matchtuple_regexp_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatchtuple_regexp_match for syntax
and options of regular expressions. Additionally, tuple_regexp_replacetuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replace
supports the option 'replace_all'"replace_all""replace_all""replace_all""replace_all""replace_all", which causes all matches
within each individual string to be replaced.
The ReplaceReplaceReplaceReplacereplacereplace expression may use the tag '$0'"$0""$0""$0""$0""$0" to refer to the
matched substring in the input data, '$i'"$i""$i""$i""$i""$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 DataDataDataDatadatadata is an empty tuple, the operator returns an empty tuple. If
ReplaceReplaceReplaceReplacereplacereplace is an empty tuple and DataDataDataDatadatadata is not empty, an
exception is raised.
Unicode 码点与字节
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')set_system("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")set_system("tsp_tuple_string_operator_mode","byte")。If
'filename_encoding'"filename_encoding""filename_encoding""filename_encoding""filename_encoding""filename_encoding" is set to 'locale'"locale""locale""locale""locale""locale" (legacy), this
operator always uses the byte mode.
HDevelop 内联操作
HDevelop provides an in-line operation for tuple_regexp_replacetuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replace,
which can be used in an expression in the following syntax:
Result := regexp_replace(Data, Expression, Replace)
执行信息
- 多线程类型:独立(即使使用独占算子也能并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
参数
DataDataDataDatadatadata (输入控制) string(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Input strings to process.
ExpressionExpressionExpressionExpressionexpressionexpression (输入控制) string(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Regular expression.
默认值:
'.*'
".*"
".*"
".*"
".*"
".*"
建议值:
'.*'".*"".*"".*"".*"".*", 'replace_all'"replace_all""replace_all""replace_all""replace_all""replace_all", 'ignore_case'"ignore_case""ignore_case""ignore_case""ignore_case""ignore_case", 'multiline'"multiline""multiline""multiline""multiline""multiline", 'dot_matches_all'"dot_matches_all""dot_matches_all""dot_matches_all""dot_matches_all""dot_matches_all", 'newline_lf'"newline_lf""newline_lf""newline_lf""newline_lf""newline_lf", 'newline_crlf'"newline_crlf""newline_crlf""newline_crlf""newline_crlf""newline_crlf", 'newline_cr'"newline_cr""newline_cr""newline_cr""newline_cr""newline_cr"
ReplaceReplaceReplaceReplacereplacereplace (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Replacement expression.
ResultResultResultResultresultresult (输出控制) string(-array) → HTupleSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Processed strings.
示例(HDevelop)
tuple_regexp_replace(['img10.bmp','img11.bmp','img12.bmp'], \
'img(.*).bmp', 'out$1.txt', Result)
* Returns ['out10.txt','out11.txt','out12.txt']
另见
tuple_regexp_matchtuple_regexp_matchTupleRegexpMatchTupleRegexpMatchTupleRegexpMatchtuple_regexp_match,
tuple_regexp_testtuple_regexp_testTupleRegexpTestTupleRegexpTestTupleRegexpTesttuple_regexp_test,
tuple_regexp_selecttuple_regexp_selectTupleRegexpSelectTupleRegexpSelectTupleRegexpSelecttuple_regexp_select
模块
基础