Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: StringMatchQ and Regular Expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88520] Re: StringMatchQ and Regular Expressions
  • From: Mark Westwood <markc.westwood at gmail.com>
  • Date: Wed, 7 May 2008 07:08:36 -0400 (EDT)
  • References: <fvhdu8$3p6$1@smc.vnet.net> <fvpd52$mqv$1@smc.vnet.net>

Ahh, I think I understand now

I had crafted my forward-looking regex to match the whole string, but
was being sloppy in my thinking about what is being matched.

My regex was intended to match "the letters d,o immediately followed
by any number of space characters followed by one or more word-
constituent characters followed by an equals sign".  Used in
StringCases this finds the first two letters of the text searched.

However, used in StringMatchQ, it fails, because the whole search text
does not match the expression.  Further, it seems that StringMatchQ
will never return True if the regex uses lookahead; when attempting to
match the whole search text there is nothing for the regex engine to
look ahead to, and never will be.

Thanks for your help, and further thought prompted by your input has
shown me how to solve the problem without lookahead anyway.

Mark



>

On 6 May, 11:50, Albert Retey <a... at arcor.net> wrote:
> Mark Westwood schrieb:
>
>
>
> > Hi
>
> > I'm running Mathematica v6.0.2 on Windows XP.
>
> > I define a regex thus:
>
> > doStmt = RegularExpression["do(?=\\s*\\w+=)"];
>
> > and then execute:
>
> > StringCases["doindex= ", doStmt]
>
> > which brings the response
>
> > {do}
>
> > I then execute
>
> >StringMatchQ["doindex= ", doStmt]
>
> > which brings the response
>
> > False

> > I had expected that if StringCases found any cases, thenStringMatchQ
> > would return True.  Obviously this is not the case, but can anyone out
> > there throw light upon this.
>
> > Thanks for any insights you can give me
>
> > Mark Westwood
>
> See also StringFreeQ and the section
> "Properties & Relations  (3)" in its homepage.
>
> hth,
>
> albert



  • Prev by Date: Re: Solving on mathematica
  • Next by Date: Re: Problem/bug with ends of thick lines in graphics
  • Previous by thread: Re: StringMatchQ and Regular Expressions
  • Next by thread: Getting the size of the bounding box of a Graphics3D[]