[英]regex pattern for http url without quotes in vb.net
我正在使用此代码,但只查找带有“”的网址
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
如果您希望字符串中包含多个URL,则需要定义将其作为分隔符的内容,例如,空格, some text http://abc http://123 nonurltext
或看起来像这样的情况您的regex some text(http://abc) some other text (http://123) some more text
,一旦有了此分隔符,就可以使用它来告诉regex如何将您真正想要的字符串归零。 如果括在括号中,则以下内容将变为http:// ... ,例如(http://www.yahoo.com)
忽略其他所有内容
Regex.Matches(test, "(?<=\()http://.+?(?=\))", RegexOptions.IgnoreCase)
您应该能够更改此设置以适合您的需要,例如,如果分隔符为空格,则只需将\\(
和\\)
替换为\\s
(表示空白)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.