TextReplace
TextReplace(text, pattern, subst, all, caseInsensitive, re)
Replaces the occurrence of «pattern» in «text» by «subst».
If «all» is omitted or False, replaces only the first occurrence. If «all» is True, replaces every occurrence of «pattern».
If «caseInsensitive» is True, matches to «pattern» in a case-insensitive fashion.
When «re» is True, then «pattern» is treated as a regular expression. You can then substitute matching sub-patterns into the result using the following escape sequences in «subst»:
\0= The matched text\1,\2, ...,\9= Text matching the numbered sub-patterns<name>= text matching a named sub-pattern.
Examples
TextReplace("One for one and one for all", "one", "two") →"One for two and one for all"
TextReplace("One for one and one for all", "one", "two", caseInsensitive: True) →"two for one and one for all"
TextReplace("One for one and one for all", "one", "two", all: True) →"One for two and two for all"
TextReplace("One for one and one for all", "one", "two", all: True, caseInsensitive: True) →"two for two and two for all"
TextReplace("The date is 01/26/2016", "(\d?\d)[/-](\d?\d)[/-](\d\d\d\d)", "\2-\1-\3",re:true,all:true)→"The date is 26-01-2016"
TextReplace("The date is 01/26/2016", "(?<M>\d?\d)[/-](?<D>\d?\d)[/-](?<Y>\d\d\d\d)", "<D>-<M>-<Y>", re: true, all: true)→"The date is 26-01-2016"
TextReplace("The date is 01/26/2016", ".*?(?<M>\d?\d)[/-](?<D>\d?\d)[/-](?<Y>\d\d\d\d).*", "<D>-<M>-<Y>", re: true, all: true)→"26-01-2016"
See Also
Comments
Enable comment auto-refresher