MathGroup Archive 2009

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

Search the Archive

Re: When a string does not match itself

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97268] Re: [mg97198] When a string does not match itself
  • From: "Ingolf Dahl" <ingolf.dahl at telia.com>
  • Date: Mon, 9 Mar 2009 05:17:51 -0500 (EST)
  • References: <200903070742.CAA17174@smc.vnet.net>

A lot of thanks to all that have responded.
This was so trivial that I simply MUST put the blame on someone else, a why
then not on Mathematica Help?
There are evidently three different types of string patterns used in
Mathematica, namely "Abbreviated String Patterns", "String Patterns", and
"Regular Expressions". They can be mixed in the same expression.

"Abbreviated String Patterns" are mentioned in "Some General Notations and
Conventions" and in the help for StringMatchQ, but not in
"guide/StringPatterns", in "tutorial/StringPatterns" or in the help for
StringExpression. They ought to be.

In the help for StringPosition it is said that "The string expression patt
can contain any of the objects specified in the notes for StringExpression",
but it is not mentioned that "Abbreviated String Patterns" could not be
used.

A string pattern is evidently something that depends on the context: A
string pattern valid for StringMatchQ does need to be valid for
StringPosition, and vice versa. 

Evidently this is a case, where the creators of Mathematica have accepted a
convention from other systems, and then have not managed to make a
consequent and systematic notation for Mathematica.

By the way, other examples of strings not matching themselves are "\\@" and
strings containing "\\*" or "\\@". 

In some of the answers it has been said that \ and * are special characters.
But they are evidently special characters very different ways: \ is always a
special character, while * (and @) are special characters just in
"Abbreviated String Patterns", if I have understood it properly. 

A last question: would it break any logic to have "\\*" matching itself
always?

Best regards

Ingolf Dahl
Sweden

> -----Original Message-----
> From: ingolf.dahl at telia.com [mailto:ingolf.dahl at telia.com] 
> Sent: den 7 mars 2009 08:43
> To: mathgroup at smc.vnet.net
> Subject: [mg97198] When a string does not match itself
> 
> This is a maybe a trivial question, but I have not found the 
> explanation in help (I am using Mathematica 7.0.0):
> 
>  
> 
> Normally a string matches itself:
> 
>  
> 
> In[270]:= StringMatchQ["monkey", "monkey"]  
> 
> Out[270]= True
> 
>  
> 
> But 
> 
>  
> 
> In[271]:= StringMatchQ["\\*", "\\*"]  
> 
> Out[271]= False
> 
>  
> 
> Why? Compare also to
> 
>  
> 
> In[4]:= StringCases["\\*", "\\*"]   
> 
> Out[4]= {"\\*"}
> 
>  
> 
> In[267]:= StringPosition["\\*", "\\*"]  
> 
> Out[267]= {{1, 2}}
> 
>  
> 
> Best regards
> 
>  
> 
> Ingolf Dahl
> 
> Sweden
> 
> ingolf.dahl at telia.com
> 
> 
> 
> 




  • Prev by Date: Re: Re: Wolfram/Alpha
  • Next by Date: Re: L-shaped ListContourPlot
  • Previous by thread: When a string does not match itself
  • Next by thread: Re: When a string does not match itself