views:

367

answers:

2

Have you used the Perl 5.10 backtracking control verbs in your regexes yet? And what problems did they help you accomplish?


Just as background: I have done some fiddling, but I can't get any really useful results.

As a comparison, when I started getting what the (?> grouping did, it started showing up more in my regexes. I liked the idea of tuning the world of Perl regex to a particular set of assumptions. As RE languages get more featured, the backtracking has made the performance of REs wildly divergent from the lean and mean FSA that they were based upon.


When someone can tell me what other implementation of REs has backtracking control verbs--and PCRE does not, I can concede that it belongs in the general area of expertise of people knowledgeable about regexes. This is a Perl regex question, and guys helping people out with Ruby, Python, C#, Javascript--or any PCRE client implementations-- probably can't help or see it as a waste of space for the tags they normally read.

+1  A: 

Honestly, I haven't even used 5.10 much yet. As great as some of the new features are I only use them in personal scripts. For production I target compatibility with 5.8. For CPAN I target 5.6. This has stopped me from playing with most of the new toys.

The backtracking control features are interesting but I can't see many applications outside of parsers. I can't imagine stuffing an entire parser into a single regex. (Even if they do support recursion now!) I'm much more excited about Perl6 grammars.

Michael Carman
I agree on grammars. But the verbs give us a little bit of that now.
Axeman
They do, but it seems more like a teaser than like anything immediately useful. There's also that little "WARNING: These patterns are experimental and subject to change or removal..." caveat in perlre.
Michael Carman
+2  A: 

It's been years since I did any Perl programming, so I didn't even know about this feature until you mentioned it. It looks like one of those hardcore feature that only regex gurus would use (of course, the Perl community has plenty of those). Perl 6 Grammars, on the other hand, look like they'll be a lot fun to play with.

For now, I'm content with atomic groups and possessive quantifiers.--in fact, I'm practically addicted to them. It's gotten to the point where I reflexively try to write regexes in such a way that they'll never backtrack. I have to remind myself sometimes that backtracking is okay in small doses, and it's not worth the effort to eliminate it completely.

p.s., As far as I know, possessive quantifiers are only supported by Java, PCRE (PHP, Apache, Flex 3/ActionScript 3), and the JGSoft regex engine used by RegexBuddy, EditPad Pro and PowerGrep.

update: The Oniguruma flavor (used in Ruby 1.9+ and TextMate) supports both atomic groups and possessive quantifiers. And of course, Perl 5.10 supports them in addition to the backtracking-control verbs.

Alan Moore