In my bash script I need to extract just the path from the given URL. For example, from the variable containing string:
http://login:password@example.com/one/more/dir/fi
url="http://login:password@example.com/one/more/dir/file.exe?a=sth&b=sth"
grep
$ grep -Po '\w\K/\w+[^?]+' <<<$url
/one/more/dir/file.exe
grep
$ grep -o '\w/\w\+[^?]\+' <<<$url | tail -c+2
/one/more/dir/file.exe
$ rg -o '\w(/\w+[^?]+)' -r '$1' <<<$url
/one/more/dir/file.exe
To get other parts of URL, check: Getting parts of a URL (Regex).