Difference between revisions of "TextReplace"
m (adding doc status category stub page) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | [[ | + | [[Category:Text Functions]] |
− | |||
− | + | == TextReplace(text, pattern, subst'', all, caseInsensitive, re'') == | |
+ | Replaces the occurrence of «pattern» in «text» by «subst». | ||
− | + | If «all» is omitted or <code>False</code>, replaces only the first occurrence. If «all» is <code>True</code>, replaces every occurrence of «pattern». | |
+ | |||
+ | If «caseInsensitive» is <code>True</code>, matches to «pattern» in a case-insensitive fashion. | ||
+ | |||
+ | When «re» is <code>True</code>, 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»: | ||
+ | : <code>\0</code> = The matched text | ||
+ | : <code>\1</code>, <code>\2</code>, ..., <code>\9</code> = Text matching the numbered sub-patterns | ||
+ | : <code><name></code> = text matching a named sub-pattern. | ||
+ | |||
+ | == Examples == | ||
+ | :<code>TextReplace("One for one and one for all", "one", "two") → </code> | ||
+ | :<code>"One for two and one for all"</code> | ||
+ | |||
+ | :<code>TextReplace("One for one and one for all", "one", "two", caseInsensitive: True) →</code> | ||
+ | :<code>"two for one and one for all"</code> | ||
+ | |||
+ | :<code>TextReplace("One for one and one for all", "one", "two", all: True) →</code> | ||
+ | :<code>"One for two and two for all"</code> | ||
+ | |||
+ | :<code>TextReplace("One for one and one for all", "one", "two", all: True, caseInsensitive: True) →</code> | ||
+ | :<code>"two for two and two for all"</code> | ||
+ | |||
+ | :<code>TextReplace("The date is 01/26/2016", "(\d?\d)[/-](\d?\d)[/-](\d\d\d\d)", "\2-\1-\3",re:true,all:true)</code> → | ||
+ | :<code>"The date is 26-01-2016"</code> | ||
+ | |||
+ | :<code>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)</code> → | ||
+ | :<code>"The date is 26-01-2016"</code> | ||
+ | |||
+ | :<code>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)</code> → | ||
+ | :<code>"26-01-2016"</code> | ||
+ | |||
+ | == See Also == | ||
+ | * [[SelectText]] | ||
+ | * [[FindInText]] | ||
+ | * [[Text Concatenation Operator: &]] | ||
+ | * [[Chr]] | ||
+ | * [[TextTrim]] | ||
+ | * [[SplitText]] | ||
+ | * [[JoinText]] | ||
+ | * [[TextUpperCase]] | ||
+ | * [[TextLowerCase]] | ||
+ | * [[Regular Expressions]] | ||
+ | * [[Text functions]] |
Latest revision as of 19:29, 23 March 2016
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