Given the URL (single line): http://test.example.com/dir/subdir/file.html
How can I extract the following parts using regular expressions:
regexp to get the URL path without the file.
url = 'http://domain/dir1/dir2/somefile' url.scan(/^(http://[^/]+)((?:/[^/]+)+(?=/))?/?(?:[^/]+)?$/i).to_s
It can be useful for adding a relative path to this url.