[forwarded submission from a non-member address -- rjk]
From: Dave Turner <[EMAIL PROTECTED]>
Date: 19 Feb 2002 18:40:14 -0500
Subject: Re: [Boston.pm] regex critique
To: "Peter R. Wood (Lists)" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
On Tue, 2002-02-19 at 17:53, Peter R. Wood (Lists) wrote:
> on 2/19/02 5:29 PM, Dave Turner at [EMAIL PROTECTED] wrote:
>
> > Is this a valid hint?
> >
> > /*+FIRST_ROWS DOMAIN_INDEX_SORT*/
>
> Perhaps. I wasn't sure if the spaces were required or not, but all the
> examples in Oracle's docs had them. I will check this out.
>
> >
> > If so, your \s+ fails. I don't use Oracle, so I can't check any of this,
> > but what about this?
> >
> > /*+ FIRST_ROWS */ /*+ DOMAIN_INDEX_SORT */
> >
> > If so, your .* should be .*?
> >
>
> .* = match a single character zero or more times, yes?
> .*? = the above condition, but only zero or one instances of the above?
> What would the .*? do for me?
? after a quantifier (?, *, or +) means non-greedy.
Consider your regexp on the above example. $1 will be FIRST_ROWS */ /*+
DOMAIN_INDEX_SORT. With non-greedy, it will match as little as possible
that makes the rest match, and $1 wil be just FIRST_ROWS. (To get
DOMAIN_INDEX_SORT too, just replace if (/.../) with while (/.../g) and
replaces = with .= or similar.
> > Are quoted strings which should not be parsed for */ included? Then
> > you'll need to do more complex stuff (see the perl faq).
> >
>
> I'm not sure what you mean by this, can you give an example?
Let's say the following is valid:
/*+ USING_STRING "foo */" DOMAIN_INDEX_SORT */
Your parser will screw up and think the */ inside the quotes ends the
hint.
> > If you use {} instead if // to delimit your RE, you'll be able to
> > replace \/ with just /, which makes your code that much more readable.
>
> Simon Cozens also mentioned this.
Yep, it's Generic Perl Wisdom (TM).
--
-Dave Turner Stalk Me: 617 441 0668
"Because it is more about listening than movement-listening to the
body's inner instrinctual wisdom from which movement springs."
--A.B., Shelburne Falls, MA (seen on a flier for "Qi Gong Therapy")