Regex to match filename in a url -
i'm wanting remove filenames url path (which doesn't contain domain) in javascript.
the path this:
/something/myfile.html?d=var or
/something/myfile.html and desired output:
/something/ sometimes urls passed in this:
/something/else i don't want 'else' stripped out. in other words regex strips after last slash not work in case.
edit: clarify, consider filename . after forward slash seen above.
remove matches following regex pattern:
[^/?]*\.[^/?]*(\?.*)?$ or really
[^/?#]*\.[^/?#]*(\?.*)?(\#.*)?$ don't forget use decodeuricomponent on what's left.
Comments
Post a Comment