Reputation:
Hi I have URL as follows:
I need to parse the above URL to get two group as folloes:
Group1 Group 2
vimeo.com/ 99612902
www.vimeo.com/ 99612902
http://vimeo.com/ 99612902
http://www.vimeo.com/ 99612902
http://vimeo.com/ 81368903
I've tried the followin regex
^((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:([^\/]*))?((\/[\w\-]+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?
but which yields me unwanted and empty group. Please help me out.
Upvotes: 1
Views: 224
Reputation: 41838
With your input, we can match both parts into Groups 1 and 2 with this:
^(.*/)(.*)
or, for your revised input:
^(.*[/=])([^/=]+$)
In the demo, see the capture groups in the right pane.
In VB.NET, you can do this:
Dim theUrl As String
Dim theNumbers As String
Try
ResultString = Regex.Match(SubjectString, "^(.*/)(.*)", RegexOptions.Multiline)
theUrl = ResultString.Groups(1).Value
theNumbers = ResultString.Groups(2).Value
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try
Option 2
If you want to do some very lightweight url validation at the same time, you can use this:
^((?:http://)?(?:www\.)?[^./]+\.\w+/)(.*)
or, with your revised input:
^((?:http://)?(?:www\.)?[^./]+\.\w+[=/])([^/=]+$)
Upvotes: 1
Reputation: 174706
Simply you could use the below regex,
^(.*\/)(.*)$
From the starting upto the last /
symbol are captured by group1. Remaining characters are captured into group2.
OR
^((?:https?:\/\/)?(?:www\.)?(?:[^.]*)\.\w+\/)(.*)$
Upvotes: 0