4 ms·
how would you even "parse" a url with a regex? dynamically defined named subpatterns for each url parameter? I think the best i could do on paper with a regex i
by elif 5y ago
how would you even "parse" a url with a regex? dynamically defined named subpatterns for each url parameter? I think the best i could do on paper with a regex is say "yup this is a url" or maybe "yup i can count the number of params"
Unless it was a specific url with specific params?
- chrismorgan 5y agoMatch groups so you can split it up into scheme, username, password, host, port, path, query, fragment. Not difficult to approximate, though for best results with diverse schemes you’d want an engine that allows repeated named groups, and I don’t know if any do (JavaScript and Python don’t).
- powersnail 5y agoPython's `regex` package does allow repeated named group.
- elif 5y agoI mean ya that would match a query string, but it wouldn't parse it?
- tyingq 5y agoI assume they meant "some regex implementation, including replace and/or match groups". Like, for just the params part (yes, broken and simplistic): #!/usr/bin/perl $_="a=b&c=d&e=f&whatever=some thing"; while (s/^([^&]*)=([^&]*)(&|$)//) { print "[$1] [$2]\n"; }