Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

StringCases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56903] StringCases
  • From: Maxim <ab_def at prontomail.com>
  • Date: Mon, 9 May 2005 01:46:57 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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