I have a line:
<https://gitlab.me.com/api/v3/projects/all?page=2&per_page=5>;
rel="next",
<https://gitlab.me.com/api/v3/projects/all?page=1&per_page=5>;
rel="first",
<https://gitlab.me.com/api/v3/projects/all?page=8&per_page=5>;
rel="last"
Thus format
(<val>; rel="key")*
And I want to parse this hash in the following format:
next => https://gitlab.me.com/api/v3/projects/all?page=2&per_page=5
first => https://gitlab.me.com/api/v3/projects/all?page=1&per_page=5
last => https://gitlab.me.com/api/v3/projects/all?page=8&per_page=5
In Java, I would use a regular expression pattern to extract each key pair => value and put them on a map. The template will look something like this:
<([^>]++)>;\s*rel="([^"]++)"
Which would give me the key in the second group of matches and the value in the first. Would the same approach be the best way to achieve this - is it Perl, or is there something eye-popping that I could do?
PS The reason I use Perl, not Java, is because there is no Java on the server.
source
share