MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

StringCases


It seems that the string matching functions don't handle patterns in  
exactly the same way as the ordinary pattern matching Mathematica  
functions:

In[1]:= StringCases["ab", s_ /; s === "a" :> s]

Out[1]= {"a"}

In[2]:= StringCases["ab", s_ :> s /; s === "a"]

Out[2]= {"a" /; "a" === "a", "b" /; "b" === "a"}

I think that it isn't mentioned anywhere in the documentation that  
StringCases/StringReplace don't understand the conditions on the  
right-hand side of the rule.

In[3]:= StringCases["abcd", (s_ ~~ "b") | (s_ ~~ "d")]

Out[3]= {"ab"}

This one is in plain disagreement with the standard pattern matching  
rules, as in e.g. Cases[{f[a, b], f[c, d]}, f[s_, b] | f[s_, d]].

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: Calling a MS-DOS command
  • Next by Date: Re: Simplifying Log to ArcCos Expressions
  • Previous by thread: Re: Ordering broken on Windows, but not Mac
  • Next by thread: Re: StringCases