Difference between revisions of "TextReplace"
(re example) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | [[ | + | [[Category:Text Functions]] |
== TextReplace(text, pattern, subst'', all, caseInsensitive, re'') == | == TextReplace(text, pattern, subst'', all, caseInsensitive, re'') == | ||
− | |||
Replaces the occurrence of «pattern» in «text» by «subst». | Replaces the occurrence of «pattern» in «text» by «subst». | ||
Line 15: | Line 14: | ||
== Examples == | == Examples == | ||
− | + | :<code>TextReplace("One for one and one for all", "one", "two") → </code> | |
− | :<code> | ||
:<code>"One for two and one for all"</code> | :<code>"One for two and one for all"</code> | ||
− | :<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>"two for one and one for all"</code> | ||
− | :<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>"One for two and two for all"</code> | ||
− | :<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>"two for two and two for all"</code> | ||
− | :<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>"The date is 26-01-2016"</code> | ||
− | :<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>"The date is 26-01-2016"</code> | ||
− | :<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> | :<code>"26-01-2016"</code> | ||
Line 48: | Line 46: | ||
* [[TextLowerCase]] | * [[TextLowerCase]] | ||
* [[Regular Expressions]] | * [[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