F
Fritz Bayer
Hello,
I have a URL and I would like to extract the domain, path and query
part by applying only A SINGLE regular expression.
What makes the problem challenging is that I want to preprend a
constant to each capturing group, if and only if, the value is non
null.
So for example the following strings should yield the following
output:
http://www.example.com/path/index.html
domain: www.example.com path: path
http://www.example.com/path/index.html?somekey=value
domain: www.example.com path: path query: somekey=value
http://www.example.com/
domain: www.example.com
The words "domain:", "path:" and "query:" are the constants, which
should be prepended if a capturing group in non empty.
Is there a single regular expression, which can solve this problem? I
don't want to depend on any perl, java or on any other code.
Fritz
I have a URL and I would like to extract the domain, path and query
part by applying only A SINGLE regular expression.
What makes the problem challenging is that I want to preprend a
constant to each capturing group, if and only if, the value is non
null.
So for example the following strings should yield the following
output:
http://www.example.com/path/index.html
domain: www.example.com path: path
http://www.example.com/path/index.html?somekey=value
domain: www.example.com path: path query: somekey=value
http://www.example.com/
domain: www.example.com
The words "domain:", "path:" and "query:" are the constants, which
should be prepended if a capturing group in non empty.
Is there a single regular expression, which can solve this problem? I
don't want to depend on any perl, java or on any other code.
Fritz