Why is there a StringExpression in the following code?
f["a b c"] //. x_String :>
StringReplace[x, (StartOfString ~~ x1__ ~~ "b" ~~ x2__ ~~ EndOfString) :> f["BBB"]]
(*
f[StringExpression[f[BBB]]]
*)
Though I can remove it, I'd rather it not appear in the first place, because I'm not sure this method is safe:
f["a b c"] //. x_String :>
StringReplace[x, (StartOfString ~~ x1__ ~~ "b" ~~ x2__ ~~ EndOfString) :> f["BBB"]] /.
StringExpression -> Sequence
(*
f[f[BBB]]
*)
StringReplace(point 3 under details): "If the Subscript[sp, i] in the replacementsSubscript[s, i]->Subscript[sp, i]do not evaluate to strings,StringReplacewill yield aStringExpressionrather than an ordinary string." – rm -rf Jul 05 '13 at 05:39f["a b c b "]//.x_String:>StringReplace[x,Shortest[x1__~~"b"~~x2__]:>f["BBB"]]this maybe more apparently why needStringExpression. – HyperGroups Jul 05 '13 at 05:46