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

查看:57
本文介绍了使用正则表达式获取 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.

我有以下内容,但没有删除#this"

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天全站免登陆