News for hackers. Stuff that matters.
Re:Fast request routing using regular expressions by nikic on Thursday February 20, 2014 @07:47AM (#7270463)
PCRE actually provides this information. There's a feature called backtracking control verbs, and one of those is (* MARK:NAME). You could put a (* MARK:A), (* MARK:B), etc at the end of every path and PCRE would tell you which of the paths was taken. However PHP does not expose this information - just like it does not expose the (?C) callout feature :(

Maybe I should implement those two things.

Note: There is no whitespace between * and MARK, but if I remove it HN formats it as an italic string.

Re:Fast request routing using regular expressions by Flenser on Thursday February 20, 2014 @07:58AM (#7270496)
It could probably be done by actually doing a replacement. Make all but the first group in each route non-capturing, and then replace it with something like " $1 $2 $3 .... $n", and count the spaces. You'd have to then do another regex just for that route with all groups capturing. So for 100 routes with 9 placeholders each you would do 1 regex replace that worst-case had to populate 100 groups, and then a second replace for the identified route to populate 9 capturing groups. Does that make sense?
Re:Fast request routing using regular expressions by joosters on Thursday February 20, 2014 @11:08AM (#7271506)
Awesome! I never knew perl (compatible) regexes had this, thanks. One day I will force myself to read the whole perlre man page...