3 ms·
Regexps with backtracks are not regular languages (IIRC, right?), does that matter here?
by llimllib 12y ago
Regexps with backtracks are not regular languages (IIRC, right?), does that matter here?
- stepstep 12y agoThat's right. Typical routing regexes will not use backreferences, so that's not really an issue here. However, most routes do have parameters implemented as capture groups (which, I believe, is also not technically a feature of regular expressions). One simple solution would be to use a big regex (the union of all the routes) to determine which route it is (in O(n) time), and then once you know the route, use another regex to parse the parameters in the URL. So each route lookup requires 2 regex matches rather than N.
- stepstep 12y agoJust re-read this and realized it's unclear: when I said O(n) time, I meant linear in the length of the URL to be parsed. The point is that with this technique, it doesn't matter how many routes there are.