需要有关使用正则表达式获取 LINK ID 的帮助吗?
我得到了这个 url 例如“http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402”
我想得到 < strong>最后一位数字,其余的可以是任何东西。
我需要这样的格式“http://www.yellowpages.com/anything...lid=randomdigitnumbers”或者只要我得到这些数字。
我在正则表达式方面的知识非常贫乏,所以请大家帮助我。
以下不起作用,
Dim r As New System.Text.RegularExpressions.Regex("http://www.yellowpages.com/.*lid=d*", RegexOptions.IgnoreCase)
Dim m As Match = r.Match(txt)
If (m.Success) Then
Dim int1 = m.Groups(1)
MsgBox("(" + int1.ToString() + ")" + "")
End If
提前谢谢您
I got this url for example "http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402"
I want to get the last digit numbers and the rest could be anything.
I need a format like this "http://www.yellowpages.com/anything.... lid=randomdigitnumbers" or as long as i get those numbers.
My knowledge is very poor in this regex thing so please guys help me.
the following did not work
Dim r As New System.Text.RegularExpressions.Regex("http://www.yellowpages.com/.*lid=d*", RegexOptions.IgnoreCase)
Dim m As Match = r.Match(txt)
If (m.Success) Then
Dim int1 = m.Groups(1)
MsgBox("(" + int1.ToString() + ")" + "")
End If
thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,为此使用正则表达式有点过分了。
您可以使用字符串函数完成同样的事情:
这超出了我的想象,所以您可能需要稍微调整一下。基本概念是 URL 中 ? 之后的部分。 (查询字符串),然后将其拆分为 = 符号,并获取结果数组的第二个元素(值)。
此外,如果查询字符串具有多个名称值对,它们将由
&
分隔,因此您需要按与号进行拆分 (&
) 首先是等号。Using Regular Expressions for this is a bit of overkill, IMO.
You could accomplish the same thing using string functions:
This is off the top of my head, so you may need to tweak it a bit. The basic concept is to the portion of the URL after the ? (the query string), and then split it on the = sign, taking the second element of the resulting array (the value).
Also, if the query string has more than one name value pair, they'll be separated by
&
, so you'll need to split on the ampersand (&
) first, then the equal signs.只需找到
lid=
并获取之后的所有内容:Just find
lid=
and get everything after that: