[forwarded submission from a non-member address -- rjk]


From: Dave Turner <[EMAIL PROTECTED]>
Date: 19 Feb 2002 17:29:34 -0500
Subject: Re: [Boston.pm] regex critique
To: "Peter R. Wood (Lists)" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]

On Tue, 2002-02-19 at 15:55, Peter R. Wood (Lists) wrote:
> Greetings,
> 
> I am still fairly a newbie with Perl regexes. So today was a momentous
> occasion that I wrote a regex without looking at a book, manual, or example,
> and had it work on the first try!
> 
> However, there is always room for improvement, so I'd appreciate if you
> could critique my work and offer any suggestions on how to improve
> robustness, performance, etc.
> 
> The regex is designed to look at an oracle/sql query, determine if there is
> a hint included, and then extract the hint. Generally hints look like this:
> 
> /*+ FIRST_ROWS DOMAIN_INDEX_SORT */
> 
> So here is my regex:
> 
> if ($query =~ /\/\*\+\s+(.*)\s+\*\//) {
>   $hint = $1;
> }

Is this a valid hint?

/*+FIRST_ROWS DOMAIN_INDEX_SORT*/

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 .*?

Are quoted strings which should not be parsed for */ included?  Then
you'll need to do more complex stuff (see the perl faq).

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.

Maybe we need a regex checklist for stuff like this -- it catches a lot
of people.

-- 
-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")

Reply via email to