Skip to content

tuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replacetuple_regexp_replace🔗

Short description🔗

tuple_regexp_replaceTupleRegexpReplaceTupleRegexpReplacetuple_regexp_replacetuple_regexp_replace — Replace a substring using regular expressions.

Signature🔗

tuple_regexp_replace( string Data, string Expression, string Replace, out string Result )void TupleRegexpReplace( const HTuple& Data, const HTuple& Expression, const HTuple& Replace, HTuple* Result )static void HOperatorSet.TupleRegexpReplace( HTuple data, HTuple expression, HTuple replace, out HTuple result )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 ) -> strHerror tuple_regexp_replace( const char* Data, const char* Expression, const char* Replace, char* Result )

Herror T_tuple_regexp_replace( const Htuple Data, const Htuple Expression, const Htuple Replace, Htuple* Result )

HTuple HTuple::TupleRegexpReplace( const HTuple& Expression, const HTuple& Replace ) const

HTuple HTuple.TupleRegexpReplace( HTuple expression, HTuple replace )

Description🔗

tuple_regexp_replaceTupleRegexpReplace applies the regular expression in Expressionexpressionexpression to one or more input strings in Datadatadata, and replaces the first matching substring using the Replacereplacereplace expression. For each input string, a processed output string is returned in Resultresultresult.

Please refer to the documentation of tuple_regexp_matchTupleRegexpMatch for syntax and options of regular expressions. Additionally, tuple_regexp_replaceTupleRegexpReplace supports the option 'replace_all'"replace_all", which causes all matches within each individual string to be replaced.

The Replacereplacereplace expression may use the tag '$0'"$0" to refer to the matched substring in the input data, '$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 Datadatadata is an empty tuple, the operator returns an empty tuple. If Replacereplacereplace is an empty tuple and Datadatadata is not empty, an exception is raised.

Unicode code points versus bytes🔗

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'"filename_encoding" is set to 'locale'"locale" (legacy), this operator always uses the byte mode.

HDevelop In-line Operation🔗

HDevelop provides an in-line operation for tuple_regexp_replaceTupleRegexpReplace, which can be used in an expression in the following syntax:

Result := regexp_replace(Data, Expression, Replace)

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

Datadatadata (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Input strings to process.

Expressionexpressionexpression (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Regular expression.

Default: '.*'".*"
Suggested values: '.*', 'replace_all', 'ignore_case', 'multiline', 'dot_matches_all', 'newline_lf', 'newline_crlf', 'newline_cr'".*", "replace_all", "ignore_case", "multiline", "dot_matches_all", "newline_lf", "newline_crlf", "newline_cr"

Replacereplacereplace (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Replacement expression.

Resultresultresult (output_control) string(-array) → (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

Processed strings.

Example🔗

(HDevelop)

tuple_regexp_replace(['img10.bmp','img11.bmp','img12.bmp'], \
                     'img(.*).bmp', 'out$1.txt', Result)
* Returns ['out10.txt','out11.txt','out12.txt']

Combinations with other operators🔗

Combinations

See also

tuple_regexp_matchTupleRegexpMatch, tuple_regexp_testTupleRegexpTest, tuple_regexp_selectTupleRegexpSelect

Module🔗

Foundation