develooper Front page | perl.perl5.porters | Postings from August 2000

Re: Proposal for \v and \V, the small- and large- cut regex operators.

From:
Jeffrey Friedl
Date:
August 8, 2000 14:37
Subject:
Re: Proposal for \v and \V, the small- and large- cut regex operators.
Message ID:
200008082136.OAA17554@ventrue.yahoo.com

Rick Delaney <rick.delaney@home.com> wrote:
|> > But Rick, I still haven't answered your first question as to what
|> > situations \v couldn't be replaced by (?>...). I wish I had a great killer
|> > example to give you, but I don't have one. Since I don't have \v at my
|> > disposal, I'm not used to thinking in those terms.
|> 
|> If you have difficulty thinking in those terms, what hope is there that
|> this will be "more within reach of the novice"?

When it comes to these not-yet-existant tools, I'm worse than a novice
because I don't even have them at my disposal to play with. That no one has
been able to use them is not a reason to not consider them.

|> > Now, consider wanting to match the first number on a line, but only if
|> > it's not after XXX. That would be:
|> > 
|> >     /\d+|XXX\V/
|>  
|> It seems like the primary purpose of this is to abort the match attempt
|> when a certain condition occurs.  If that is the case, I'd rather see
|> something like:
|> 
|>     /XXX\F|\d+/;# abort if XXX, else match digits
|> 
|> where \F means fail.

You're right in the analysis of the particular example, but \V and \v could
be used for much more than that. In any case, I can see that \F would be a
good addition as well. It could always be mimiced by the sequence /\V(?!)/,
but perhaps \F would be a less-useful but more-approachable version of what
\V might often be used for.

As it's been presented, \F or \V(?!) are apparently currently doable via a
trapped (?{ die }), but something like \v(?!) (to abort the current
at-this- particular-position attempt, so the regex is immediately applied
at the next character position in the string) is not. There's just no way
to do that now, which is one reason that \v could be so useful.

Of course, "die now" use of \v is not its only use. The "okay, so I've
found some special case and now all bets other than what flows from here
are off" use is also compelling.

	Jeffrey
------------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@yahoo-inc.com> Yahoo! Finance http://finance.yahoo.com




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About