help with regular expression pattern

ddurose

New member
Joined
Jun 21, 2007
Messages
1
Programming Experience
5-10
Hi, I am trying to modify a regular expression so that it will properly convert text that resembles a hyperlink into the actual HTML code (a href). I have a slight problem with the pattern that I am using. It doesn't capture any parameters on the end of the URL if it has any. For instance, it captures http://www.somewebsite.com/ just fine, but it doesn't capture http://www.somewebsite.com/test.aspx?someparm=1&otherparm=2 properly. It doesn't catch everything from the ? over. Here is the code:

Dim patternSite As String = "\w*[\://]*\w+\.\w+\.\w+[/\w+]*[.\w+]*"

Thanks!
 
Hi, I am trying to modify a regular expression so that it will properly convert text that resembles a hyperlink into the actual HTML code (a href). I have a slight problem with the pattern that I am using. It doesn't capture any parameters on the end of the URL if it has any. For instance, it captures http://www.somewebsite.com/ just fine, but it doesn't capture http://www.somewebsite.com/test.aspx?someparm=1&otherparm=2 properly. It doesn't catch everything from the ? over. Here is the code:

Dim patternSite As String = "\w*[\://]*\w+\.\w+\.\w+[/\w+]*[.\w+]*"

Thanks!

Make it simpler:

\w+://\S+

One or more word characters, followed by :// followed by one or more non-whitespace characters

Dont put :// in a character class.

Your regex would match /:://///::::/::/a.a.a////////aaasd.a.sd.qwee as a url..

Or make it more complex:

http://internet.ls-la.net/folklore/url-regexpr.html
 
Back
Top