validUrlPathAll top-level constant

String const validUrlPathAll

The whole path of a URL.

This is not validUrlPath*, which is what twitter-text writes and what this used to be. A star over that alternation is quadratic in the length of the path: https://a.com/ followed by 3000 (a) groups took 1.3 seconds to extract. The engine matches the whole path on the first iteration either way — the cost is the other branches being retried against every prefix the first one could have stopped at.

Two changes, neither of which moves the language:

  • the ending characters are parenthesized, so one run can end on a paren group instead of needing a second iteration of the star to pick it up;
  • the @user/ branch is dropped, because it matches nothing a run does not: it is path characters ending on /, and / is a character a path is allowed to end on.

What is left is a star over a single, unambiguous run.

Implementation

const validUrlPathAll = '(?:$_validUrlPathRun)*';