5 ms·
Incidentally, here's how I might write that URL regex with comprehensibility outweighing all else. Notice that I enable free-spacing [0], which can usually be e
by Twisol 8y ago
Incidentally, here's how I might write that URL regex with comprehensibility outweighing all else. Notice that I enable free-spacing [0], which can usually be enabled by passing a flag rather than embedding it in the regex. In Python, the re.X (or re.VERBOSE) flag does the job.
(?x) # free-spacing
(?P<protocol> [a-z]{3,10} ) :// # http://
(?P<domain> [^/?#]* ) # google.com
(?P<path> [^?#]* ) # /path/to/resource
(\? (?P<query> [^#]* ))? # ?id=123
(\# (?P<fragment> .* ))? # #section
[0] https://www.regular-expressions.info/freespacing.html https://www.regular-expressions.info/freespacing.html