Junaid Rehman
Junaid Rehman

Reputation: 159

regex pattern for http url without quotes in vb.net

i am using this code, but it only looks for URLs with " "

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

Upvotes: 0

Views: 869

Answers (1)

Jason
Jason

Reputation: 3960

If you expect to have multiple URL's in your string then you need to define what will be their separator, for example, a blank space some text http://abc http://123 nonurltext or like it seems to be the case based on your regex some text(http://abc) some other text (http://123) some more text, once you have this delimeter, then you can use it to tell regex how to zero in on the string you really want. The following will get http://... if it's enclosed in parenthesis, like (http://www.yahoo.com) ignoring everything else

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

You should be able to just change this to suit your needs, for example if your delimeter were blank spaces, then just replace \( and \) with \s (means blank space)

Upvotes: 1

Related Questions