0

我正在使用此代码,但它只查找带有“”的 URL

Dim html As String = txtSource.Text
Dim mc As MatchCollection = Regex.Matches(html, """(http://.+?)""", RegexOptions.IgnoreCase)
For Each m As Match In mc
lstReapedLinks.Items.Add(m.Groups(1).Value)
Next
4

1 回答 1

1

如果您希望在您的字符串中有多个 URL,那么您需要定义它们的分隔符,例如,一个空格some text http://abc http://123 nonurltext或基于您的 regex 似乎是这种情况some text(http://abc) some other text (http://123) some more text,一旦您有了这个分隔符,那么您可以使用它告诉正则表达式如何将你真正想要的字符串归零。以下将获得http://...如果它被括在括号中,就像(http://www.yahoo.com)忽略其他所有内容一样

Regex.Matches(test, "(?<=\()http://.+?(?=\))", RegexOptions.IgnoreCase)

您应该能够根据您的需要进行更改,例如,如果您的分隔符是空格,则只需替换和\((表示空格)\)\s

于 2013-06-06T23:26:04.137 回答