使用正则表达式获取url的最后一部分 [英] Get last part of url using a regex

查看:859
本文介绍了使用正则表达式获取url的最后一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用正则表达式获取URL的最后一部分,这是我的URL,我想要在最后一个正斜杠和#

How do I get the last part of the a URL using a regex, here is my URL, I want the segmeent between the last forward slash and the #

http://mycompany.com/test/id/1234#this

所以我只想得到 1234

我有以下但是没有删除'#这个'

I have the following but is not removing the '#this'

".*/(.*)(#|$)",

索引数据时我需要这个,所以不要使用URL类。

I need this while indexing data so don't want to use the URL class.

推荐答案

如何:

".*/([^/#]*)(#.*|$)"

这篇关于使用正则表达式获取url的最后一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆