简体   繁体   English

使用RegEx匹配URL中的ID

[英]Match on ID in URL with RegEx

I am looking to find a random alpha-numeric ID from a URL returned in some JSON. 我正在寻找一些JSON返回的URL中的随机字母数字ID。 Using the example: 使用示例:

"responseURL" : "http://sutureself.com/userid/123abc"

... I want to just match on the 123abc . ...我只想匹配123abc So far I have: 到目前为止,我有:

http://sutureself.com/userid/([a-z0-9]+)

... but this matches the whole URL. ...但这与整个URL匹配。 What do I need to add to only match this ID? 我需要添加什么才能只匹配此ID? Note, the length of the ID can differ. 请注意,ID的长度可以不同。

How about this: 这个怎么样:

[^/]+(?="})

Working regex example: 工作正则表达式示例:

http://regex101.com/r/pT3fG8 http://regex101.com/r/pT3fG8

Looks like you need to set the template to "$1". 看起来您需要将模板设置为“ $ 1”。 See comments in this related post. 请参阅相关文章中的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM