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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -