The following works as expected.
StringReplace["xxxyxz", "x" ~~ _ -> "ww"]
"wwwwww"
And so does this.
StringReplace["xxxyxz", {"xy" -> "xy", "x" ~~ _ -> "ww"}]
"wwxyww"
I expected the following to return "wwxyww"
as well, but it emits an error message and returns unevaluated.
StringReplace["xxxyxz", Except["xy", "x" ~~ _] -> "ww"]
StringExpression::invld: Element Except[xy, x ~~ _] is not a valid string or pattern element in Except[xy, x ~~ _]. >>
StringReplace["xxxyxz", Except["xy", "x" ~~ _] -> "ww"]
I got this result in both V9 and V10. It looks like a bug to me, but before I report it as such, I thought I would ask the community whether or not this is actually valid behavior and, if it is valid, why?
Except
used in string operations support your assertion. Can you point me to anywhere it is explicitly documented? Your 2nd comment can be applied not only to this toy problem, but to my real problem as well. If you write it up I will up-vote it and accept it. $\endgroup$Except
can be used to match either a single character or a string position. It also implicitly suggests that the only valid arguments are those patterns listed within the sections detailing classes of characters or positions in strings. Experimentation supports this interpretation. All of this requires a pretty close reading -- I would prefer more direct statements of these points within the documentation. $\endgroup$