需要有关使用正则表达式获取 LINK ID 的帮助吗?

发布于 2024-12-17 04:25:54 字数 653 浏览 6 评论 0原文

我得到了这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那支青花 2024-12-24 04:25:54

在我看来,为此使用正则表达式有点过分了。

您可以使用字符串函数完成同样的事情:

Dim url As String = "http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402"

Dim queryString As String = url.SubString(url.IndexOf("?"), url.Length - url.IndexOF("?"))

Dim nameValuePairs As String() = queryString.Split("=")

Dim lid As String = nameValuePairs(1)

这超出了我的想象,所以您可能需要稍微调整一下。基本概念是 URL 中 ? 之后的部分。 (查询字符串),然后将其拆分为 = 符号,并获取结果数组的第二个元素(值)。

此外,如果查询字符串具有多个名称值对,它们将由 & 分隔,因此您需要按与号进行拆分 (& ) 首先是等号。

Using Regular Expressions for this is a bit of overkill, IMO.

You could accomplish the same thing using string functions:

Dim url As String = "http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402"

Dim queryString As String = url.SubString(url.IndexOf("?"), url.Length - url.IndexOF("?"))

Dim nameValuePairs As String() = queryString.Split("=")

Dim lid As String = nameValuePairs(1)

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.

老街孤人 2024-12-24 04:25:54

只需找到 lid= 并获取之后的所有内容:

Dim url As String = "http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402"
Dim lidIndex As Integer = url.IndexOf("lid=") + "lid=".Length
Dim lid As Integer = url.Substring(lidIndex)

Just find lid= and get everything after that:

Dim url As String = "http://www.yellowpages.com/manhattan-beach-ca/mip/marriott-manhattan-beach-4933923?lid=185795402"
Dim lidIndex As Integer = url.IndexOf("lid=") + "lid=".Length
Dim lid As Integer = url.Substring(lidIndex)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文