• 0

[VB.NET] Regex grouping


Question

Here's my regex that checks for valid http URL's (it allows anything for the path because I don't know exactly what is/isnt valid yet):

^(http\://)?((([a-z0-9]){1}(-|\.)?)+\.[a-z]{2,6}|((2[0-4]\d|25[0-5]|[01]?\d?\d)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?))(\:(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d\d\d|[0-5]?\d?\d?\d?\d))?(/.*)?$

The address is in blue, the port is in green, and the path is in red. I need to get each of them into some variables (so I can create a tcp socket and connect) but I'm at a loss and cant find any information about doing it in vb.net with regex grouping. Help please :pinch:

Also if you see anything wrong with the regex (not allowing correct urls, allowing fake urls, etc), let me know :)

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Found the answer myself, but I thank the few people that actually cared to read this thread :rolleyes:

For anyone coming here via search in the future, here's how you can do it:

Dim MyExpression As New System.Text.RegularExpressions.Regex("(your) cool (regex) goes (here)")
MsgBox(MyExpression.Replace("and your cool regex goes here", "'$1' is the first group, '$2' is the second group, '$3' is the third group"))

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.