MathGroup Archive 2009

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

Search the Archive

Re: When a string does not match itself

  • To: mathgroup at
  • Subject: [mg97202] Re: [mg97198] When a string does not match itself
  • From: Bob Hanlon <hanlonr at>
  • Date: Sun, 8 Mar 2009 05:49:38 -0500 (EST)
  • Reply-to: hanlonr at

"\" has a special meaning in strings. 
\n is new line, \t is tab, and otherwise \ is a literal directive

Print["This is \ttab and \
 newline\nliteral quote\" and literal \
 backslash\\ or \\\nat the end of a line"]

This is 	tab and newline
literal quote" and literal backslash\ or \
at the end of a line

And * is a wildcard in strings

StringMatchQ[#, "mon*ey"] & /@
 {"money", "monkey", "monk's key"}


Except when it is made literal

StringMatchQ[#, "mon\*ey"] & /@
 {"money", "monkey", "monk's key"}


StringMatchQ["\\*", "\\*"]


I suspect that because of the multiple special characters and how and when that they are internally evaluated, that this is comparing different expressions than what you intended.

StringMatchQ["\\", "\\"]


StringMatchQ["\*", "\*"]


StringMatchQ["\"", "\""]


Bob Hanlon

---- ingolf.dahl at wrote: 

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




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


ingolf.dahl at

  • Prev by Date: Re: Re: Re: "Do What I Mean" - a suggestion for
  • Next by Date: Re: String substitution system
  • Previous by thread: Re: When a string does not match itself
  • Next by thread: Re: When a string does not match itself