---------- Forwarded message ----------
From: Jay Savage <[EMAIL PROTECTED]>
Date: Apr 15, 2006 2:58 PM
Subject: Re: regex matching conditionally
To: "John W. Krahn" <[EMAIL PROTECTED]>


On 4/15/06, John W. Krahn <[EMAIL PROTECTED]> wrote:
> Jay Savage wrote:
> > On 4/14/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:
> >>
> >>Timothy Johnson wrote:
> >>>Will the string always have the two quotes in the same place and only
> >>>one per string?  What about something like this?
> >>>
> >>>/.*?\{([^\}]*)\}(?=.*")/gi
> >>I tested it out and it appears to be perect! Thank Mr. Johnson :)
> >>
> >>I love when I learn a new tidbit!
> >
> > A couple of things here.
> >
> > * You're not matching anything alphabetic here, so the "i" modifier is
> > superfluous.
> > * Using "^" in a class to limit a search is usually less efficient
> > than doing a 'non-greedy" search.
> > * Curly braces aren't metacharacters. they only need to be escaped
> > when they could be mistaken for range delimiters.
> >
> > If you're going through a few thousand iterations, you'll be happier
> > with something like:
> >
> >    /.*?{(\.*?)}(?=.*")/go
>
> The /o modifier only applies if you have variables in the regular expression.
>
> perldoc -q /o
>
> The .*? at the beginning is superfluous.  You have a backslash in front of the
> '.' character which means you want to match only a literal '.' character.
>

Yeah I caught the '\' after I hit send. Didn't hit delete enough
times. You're right about the .*?, too, although at the time I thought
the original suggestion had it there for a reason.

As for the 'o' modifier, that's interesting. So Perl automatically
optimizes and only compiles static regex once? That makes sense, and
I've kind of always suspected it, but I've never found anything about
it in the docs. perlretut says that it only interpolates variables
once, but that's in the section on variables. The other docs (e.g.
perlreref) all just say, "only compile regex once," which implies that
regex that don't use it a compiled each time they're encountered,
regardless.

Thanks,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!


--
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to