Arbortext Command Language > Functions by Alphabetical Listing > gsub
  
gsub
gsub(regexp, repl[, string,lvalue])
 
This function globally replaces all substrings of string that match the regular expression regexpr and replaces the substring with the string repl. The resulting string is assigned to lvalue, which must be a variable name or array element. If string is omitted, then the value of lvalue is used as the source string. When copying the string to lvalue, the part that was matched by regexpr is replaced according to the string repl.
If repl contains a “&” or “\0”, then it is replaced with the substring that matched regexpr. If repl contains a “\n”, where n is a digit between 1 and 9, then it is replaced with the substring that matched the nth parenthesized subexpression of regexpr. n must not be greater than the number of parenthesized expressions in regexpr.
gsub returns the number of substrings that were replaced or 0 if no match occurred. The lvalue is not changed if 0 is returned.
* 
Because both the regular expression parser and the ACL parser interpret backslash sequences in strings, you must use at least two backslashes to match or substitute a single "\" character in regexp or repl. If you use double quotes to delimit string constants, you must use quadruple backslashes to match or substitute a single "\".
Examples
For the example, where $x = "this":
gsub('t', 'T', $x), $x results in "This".
In another example, after
gsub('\((a)(b)\)', '(\2\1)', "(ab)c(ab)c", $r)
is executed, the value of $r is (ba)c(ba)c.
Related topic
Using regular expressions