Don’t quote regex patterns in Bash [[ ]] tests, because they’ll match literally.
So the below won’t match because it’s looking for a literal $ in the string,
instead of matching at the end of the string:
file="https://example.com/blog-post/index.html"
[[ "$file" =~ "/index.html$" ]] && echo MATCHBut this will:
file="https://example.com/blog-post/index.html"
[[ "$file" =~ /index\.html$ ]] && echo MATCHNote: [[ ]] is a Bash extension of the test command that supports regexes (among other things).
The [ ] is the POSIX standard test (see man test),
so [[ ]] features may not work in other shells or in limited shells like ash or sh.
I learned this while removing index.html from file paths to bust Cloudflare’s cache for directory listings/pretty URLs.
I then used parameter expansion to replace the match with an empty string, so directory URLs are also purged:
echo ${file/index.html/}