1

I am using Network.URI to parse a url (String). How can I get from the returned URI (parseUri url) the last part of the path? Or there are better alternatives than Network.URI?

For example from: http://www.foo.com/foo1/foo2/bar.html?q=2&q2=x#tag

I would like to get just "bar.html"

1 Answer 1

2

You can quite easily extract just the final part from a URI.

Extract the uriPath from the parsed URI, and then just take in reverse until you hit a slash.

For example,

getFinalPart :: URI -> String
getFinalPart = reverse . takeWhile (/='/') . reverse . uriPath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.