rexSubstitute
rexSubstitute(t_string) =>t_result/nil
Description
Substitutes the pattern tags in the argument string with previously matched (sub)strings.
Copies the argument string and substitutes all pattern tags in it by their corresponding matched strings in the last string matching operation. The tags are in the form of '\n', where n is 0-9. '\0' (or '&') refers to the string that matched the entire regular expression and \k refers to the string that matched the pattern wrapped by the k’th \(...\) in the regular expression.
Arguments
Value Returned
|
Copy of the argument with all the tags in it being substituted by the corresponding strings. |
|
|
The last string matching operation failed (and none of the pattern tags are meaningful). |
Examples
rexCompile( "[a-z]+\\([0-9]+\\)" )
=> t
rexExecute( "abc123" )
=> t
rexSubstitute( "*\\0*" )
=> "*abc123*"
rexSubstitute( "The matched number is: \\1" )
=> "The matched number is: 123"
rexExecute( "123456" )
=> nil ; match failed
rexSubstitute( "-\\0-")
=> nil
rexCompile("^teststr")
=> t
s="teststr_1"
rexExecute(s)
rexSubstitute("&")
=> "teststr"
rexSubstitute("[&]")
=> "[teststr]"
Related Topics
Return to top