Re:Fast request routing using regular expressions
by nikic on Thursday February 20, 2014 @08:11AM
(#7270546)
Not sure I understand this comment. Your code snippet uses named subpatterns, but not within a (?| group. The interesting question is whether you can combined those two. Without (?| you can use named captures in PCRE as well (there's just little point in this context as a non-named capture would do equally well and be more efficient.)
Re:Fast request routing using regular expressions
by zimpenfish on Thursday February 20, 2014 @08:38AM
(#7270633)
Oh, hmm, yeah, fair point. I was mistakenly assuming that using named captures would obviate the creation of N spurious capture groups but a quick benchmark proves that horribly wrong. Sorry all!
Re:Fast request routing using regular expressions
by BugBrother on Thursday February 20, 2014 @08:07AM
(#7270529)
Nice to see code. :-)
Perl 5.10 from 2007 supports named captures. (Google confirmed that.)
Edit: nikic in the parallel comment is correct, named captures are affected the same way in Perl's regexp engine with ?|. (Google perlre and search for ?|.)
Given `(?<g1>Sat)urday|(?<g2>Sun)day`, and a successful match, either `$+{g1}` or `$+{g2}` will hold the relevant subpart.
Quickie demo script: