|
|
|
|
|
by repsilat
2900 days ago
|
|
> A more understandable way to process such a string would be to split it into constituent parts and use regex only for validation Split the regex, or split the URL itself? I kinda think the split regex is pretty reasonable: protocol = "[a-z]{3,10}://"
domain = "([^/?#]*)"
path = "([^?#]*)"
query = "(?:\?([^#]*))?"
fragment = "(?:#(.*))?"
url = protocol + domain + path + query + fragment
Not so terse now though, probably has to be wrapped in a function now (or stored as a constant somewhere else.) |
|
It could be simpler, but I want the resulting data structure to be easier to use.
Example usage: A more advanced usage would be with an actions class.Basically Perl 6 treats regular expressions as code that is written in a domain specific sub-language, with grammars acting as a structure to hang them off of.