StringReplaceList["string",ssp] or StringReplaceList["string",{s1sp1,s2sp2,…}]
gives a list of the strings obtained by replacing each individual occurrence of substrings in "string" matching the string expressions si.
StringReplaceList["string",srules,n]
gives a list of the first n results obtained.
StringReplaceList[{s1,s2,…},srules]
gives the list of results for each of the si.
StringReplaceList
StringReplaceList["string",ssp] or StringReplaceList["string",{s1sp1,s2sp2,…}]
gives a list of the strings obtained by replacing each individual occurrence of substrings in "string" matching the string expressions si.
StringReplaceList["string",srules,n]
gives a list of the first n results obtained.
StringReplaceList[{s1,s2,…},srules]
gives the list of results for each of the si.
Details and Options
- The string expressions si can contain any of the objects specified in the notes for StringExpression.
- In each of the results returned by StringReplaceList only one substring has been replaced.
- StringReplaceList goes through a string, testing substrings that start at each successive character position. On each substring, it tries in turn each of the transformation rules you have specified, returning a result for each one that applies.
- StringReplaceList in effect carries out a single step in the evolution of a multiway system.
- If the spi in the replacements si->spi do not evaluate to strings, StringReplaceList will yield a StringExpression rather than an ordinary string.
- In replacements of the form si:>spi, the spi are not evaluated until each time they are used.
- StringReplaceList takes the following option:
-
IgnoreCase False whether to turn off case-sensitive matching - Setting the option IgnoreCase->True makes StringReplaceList treat lowercase and uppercase letters as equivalent.
Examples
open all close allBasic Examples (2)
Scope (9)
StringReplaceList["ababababab", _ ~~ "ab" ~~ _ -> "X"]StringReplaceList["abcd acbd", RegularExpression["[ab]"] -> "XX"]Use pattern matching for dates:
StringReplaceList["date:31/12/2003", DatePattern[{"Day", "Month", "Year"}] -> "XX"]Mixed regular expressions and string patterns:
StringReplaceList["abcd acbd", RegularExpression["[ab]"] ~~ _ -> "YY"]Use RuleDelayed (:>) in order to evaluate the right-hand side of a rule:
StringReplaceList["101abcd102abcd", a : DigitCharacter.. :> ToString[ToExpression[a] ^ 2]]Generate at most two possible results:
StringReplaceList["abcddbbcbbbacbbaa", "bb" -> "X", 2]Replace occurrences of either string:
StringReplaceList["abcdabcdaabcabcd", {"abc" -> "Y", "d" -> "XXX"}]StringReplaceList works on special characters:
StringReplaceList["product: A ⊕ (B ⊕ C)" , "⊕" -> "x"]StringReplaceList automatically threads over lists of strings:
StringReplaceList[{"aaabbbbaaaa", "bbbaaaab", "aaabab"}, "ab" -> "X"]Options (1)
IgnoreCase (1)
Applications (2)
Five steps in the evolution of the Fibonacci multiway system [more info]:
NestList[Union[Flatten[StringReplaceList[#, {"A" -> "AB", "B" -> "A"}]]]&, {"A"}, 5]Two steps in the evolution of another multiway system:
NestList[Union[Flatten[StringReplaceList[#, {"AB" -> "ABBA", "ABB" -> ""}]]]&, {"ABBAAB"}, 2]All possible replacements of the form
:
StringReplaceList["abcaaba", ("a" ~~ x___ ~~ "a") :> ToUpperCase[x]]Possible Issues (1)
StringReplaceList yields a StringExpression if the rule does not have a string result:
StringReplaceList["abc", "c" -> a]FullForm[%]See Also
Tech Notes
Related Guides
History
Introduced in 2004 (5.1)
Text
Wolfram Research (2004), StringReplaceList, Wolfram Language function, https://reference.wolfram.com/language/ref/StringReplaceList.html.
CMS
Wolfram Language. 2004. "StringReplaceList." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StringReplaceList.html.
APA
Wolfram Language. (2004). StringReplaceList. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringReplaceList.html
BibTeX
@misc{reference.wolfram_2026_stringreplacelist, author="Wolfram Research", title="{StringReplaceList}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/StringReplaceList.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stringreplacelist, organization={Wolfram Research}, title={StringReplaceList}, year={2004}, url={https://reference.wolfram.com/language/ref/StringReplaceList.html}, note=[Accessed: 13-June-2026]}