开发者

What Regular Expression can I use to remove all characters from a url after the last /

When given a full URL I need a regular expression that I can use to replace everything after the final slash with nothing, i.e.

http:// www.somewhere.com/someplace/subsomeplace/default.aspx

would return

http:// www.somewhere.com/someplace/subsomeplace/

and

http:// www.somewhere.com/someplace/subsomeplace

would return

http:// www.somewhere.com/so开发者_JAVA百科meplace/

The spaces in the URLs above are not really there I needed to remove them because Stack Overflow won't let me post more then 2 URLs


/[^\/]*$/

This will give you the part you need.

Rubular link: http://rubular.com/r/zJlu1O5SqC

JavaScript example, tested in FireBug:

"http://www.somewhere.com/someplace/subsomeplace/default.aspx".match(/[^\/]*$/g);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜