Purpose
Replaces all/single RegEx matches in a string and returns modified string after doing a RegEx match replace. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
RegExReplace$(input_string, expression_string, replace_text,
[, case_insensitive ] [, replace_all ] )
input_string (String): A string with the target sequence (the subject) against which the RegEx expression is matched and replaced.
expression_string (String) : The RegEx pattern to match the string to.
replace_text (String) : The string with the replacement text.
case_insensitive (Logical) : Character matching should be performed without regard to case. (This parameter is Optional) (default value is TRUE)
replace_all (Logical) : Replace all matches in string or not (This parameter is Optional) (default value is TRUE).
Return Value
Logical
Description
Use the RegexReplace$() function to replace all/single RegEx matches in a string. This function returns a modified string after doing RegEx match replace.
case_insensitive is optional and defaults to TRUE.
Examples
print RegExReplace$("file name is foo.txt", "([a-z]+)(\.txt)", "$1.dat")
//returns "file name is foo.dat"
print RegExReplace$("file name is foo.txt", "([a-z]+)(\.txt)", "unknown")
//returns "file name is unknown"
print RegExReplace$("file name is foo.TXT", "([a-z]+)(\.txt)", "unknown", FALSE)
//returns "file name is foo.TXT"
print RegexReplace$("foo.txt to foo1.txt", "(\w+).txt", "$1.dat")
//returns "foo.dat to foo1.dat"
print RegexReplace$("foo.txt to foo1.txt", "(\w+).txt", "$1.dat", TRUE, FALSE)
//returns "foo.dat to foo1.txt"