info.mailtraq.com > Management > Script Functions A-Z > WildcardMatchReplace() WildcardMatchReplace()Compares an input string with a wildcarded expression string and, via substitution using placeholders in a replacement string, returns an output string. String matches are case insensitive and the original case of input string characters are preserved if they appear in output string.
The input string must be less than 250 characters. Wildcards permitted in the expression string are ? (ASCII 63), which represents any single character, and * (ASCII 42) which matches zero or more characters. The placeholder used to generate the output string in the replacement string is $ (ASCII 36) and derivatives with numerical modifiers, for example $1 and $2 representing, respectively, the first and second wildcards in the expression string.
The expression string is pattern matched from right to left on the input string and returns the entire input string if the expression string cannot be anchored in the input string. As for the WildcardMatch() function, the * wildcard represents zero or more characters unless matching to the right hand end of the input string when it represents one or more characters.
output := WildcardMatchReplace( input , expression , replacement )
- input
- The input string
- expression
- A wildcarded string expression
- replacement
- A string containing placeholders which correspond to order of the wildcards used in expression
- output
- The output string
"quick" := WildcardMatchReplace("The quick brown fox",
"*the * brown*", "$2")
"Hello fox" := WildcardMatchReplace("The quick brown fox",
"*brown *", "Hello $2")
"The quick brown fox" := WildcardMatchReplace(
"The quick brown fox", "* fox*", "$1")
Compare the result with the above when the right hand end of the input string is padded with a trailing space "The quick brown" := WildcardMatchReplace("The quick brown fox ",
"* fox*", "$1")
The following expression demonstrates the use of placeholders "Version1.27 [eng]" := WildcardMatchReplace(
"Build 0027 Release 1 (eng)",
"Build ???? Release * (*)", "Version $5.$3$4 [$6]")
Clarification of placeholder values $1="0", $2="0", $3="2", $4="7", $5="1", $6="eng" |