({{, (RefLink[StringReplaceList, paclet:ref/StringReplaceList])["string",s->sp] or (RefLink[StringReplaceList, paclet:ref/StringReplaceList])["string",{(Subscript[s, 1])->(Subscript[sp, 1]),(Subscript[s, 2])->(Subscript[sp, 2]),…}]
gives a list of the strings obtained by replacing each individual occurrence of substrings in "string" matching the string expressions (Subscript[s, i]). }, {, (RefLink[StringReplaceList, paclet:ref/StringReplaceList])["string",srules,n]
gives a list of the first n results obtained. }, {, (RefLink[StringReplaceList, paclet:ref/StringReplaceList])[{(Subscript[s, 1]),(Subscript[s, 2]),…},srules]
gives the list of results for each of the (Subscript[s, i]). }})

OpenersNotesSection(Spacer1)Details and Options

The string expressions (Subscript[s, i]) can contain any of the objects specified in the notes for (RefLink[StringExpression, paclet:ref/StringExpression]).

In each of the results returned by (RefLink[StringReplaceList, paclet:ref/StringReplaceList]) only one substring has been replaced.

(RefLink[StringReplaceList, paclet:ref/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.

(RefLink[StringReplaceList, paclet:ref/StringReplaceList]) in effect carries out a single step in the evolution of a multiway system.

If the (Subscript[sp, i]) in the replacements (Subscript[s, i])->(Subscript[sp, i]) do not evaluate to strings, (RefLink[StringReplaceList, paclet:ref/StringReplaceList]) will yield a (RefLink[StringExpression, paclet:ref/StringExpression]) rather than an ordinary string.

In replacements of the form (Subscript[s, i]):>(Subscript[sp, i]), the (Subscript[sp, i]) are not evaluated until each time they are used.

Setting the option (RefLink[IgnoreCase, paclet:ref/IgnoreCase])->(RefLink[True, paclet:ref/True]) makes (RefLink[StringReplaceList, paclet:ref/StringReplaceList]) treat lowercase and uppercase letters as equivalent.

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Make replacements for "c" in all possible ways:

StringReplaceList["ccccc","c"->"XYX"]

StringReplaceList["abcdeabacde",{"abc"->"X","cde"->"Y"}]

OpenersExampleSection1(Spacer1)Scope  (9)

Use string patterns:

StringReplaceList["ababababab",_~~"ab"~~_->"X"]

Use a regular expression:

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 (RefLink[RuleDelayed, paclet:ref/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"}]

(RefLink[StringReplaceList, paclet:ref/StringReplaceList]) works on special characters:

StringReplaceList["product: A ⊕ (B ⊕ C)" ,"⊕"->"x"]

(RefLink[StringReplaceList, paclet:ref/StringReplaceList]) automatically threads over lists of strings:

StringReplaceList[{"aaabbbbaaaa","bbbaaaab","aaabab"},"ab"->"X"]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)IgnoreCase  (1)

Make replacements for "c" in all possible ways, including uppercase letters:

StringReplaceList["ccbbCbcc","c"-> "X",IgnoreCase-> True]

There are fewer results when taking case sensitivity into account:

StringReplaceList["ccbCbcc", "c"-> "X"]

OpenersExampleSection3(Spacer1)Applications  (2)

Five steps in the evolution of the Fibonacci multiway system (WebLink[[more info]:, http://www.wolframscience.com/nksonline/page-205])

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 axy…za ⟶ aXY…Za:

StringReplaceList["abcaaba",("a"~~x___~~"a"):>ToUpperCase[x]]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

(RefLink[StringReplaceList, paclet:ref/StringReplaceList]) yields a (RefLink[StringExpression, paclet:ref/StringExpression]) if the rule does not have a string result:

StringReplaceList["abc","c"-> a]

FullForm[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[StringReplace, paclet:ref/StringReplace])  ▪  (RefLink[ReplaceList, paclet:ref/ReplaceList])  ▪  (RefLink[StringCases, paclet:ref/StringCases])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Operations on Strings, paclet:tutorial/OperationsOnStrings])}, {▪(RefLinkPlain[Special Characters, paclet:tutorial/SpecialCharacters-StringsAndCharacters])}, {▪(RefLinkPlain[String Patterns, paclet:tutorial/StringPatterns])}, {▪(RefLinkPlain[Working with String Patterns, paclet:tutorial/WorkingWithStringPatternsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}, {▪(RefLinkPlain[Computational Systems, paclet:guide/ComputationalSystemsAndDiscovery])}, {▪(RefLinkPlain[Iterated Maps & Fractals, paclet:guide/IteratedMapsAndFractals])}, {▪(RefLinkPlain[String Operations, paclet:guide/StringOperations])}})}})