Split regular expression in C#.net

i need to split the regular expression @"^(\S*)/([^/]+)-l(\d+).html" in C#.net
Example url is testing/testing1/whitebox-testing-l4.html
I need Group[1] = testing/testing1
Group[2] = whitebox-testing
Group[3] = 4
LVL 2
uvalsAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0
 
ddrudikCommented:

C#.NET Code Example:
using System;
using System.Text.RegularExpressions;
namespace myapp
{
  class Class1
    {
      static void Main(string[] args)
        {
          String sourcestring = "source string to match with pattern";
          Regex re = new Regex(@"^(\S*)/([^/]+)-l(\d+)\.html");
          MatchCollection mc = re.Matches(sourcestring);
          int mIdx=0;
          foreach (Match m in mc)
           {
            for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
              {
                Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames()[gIdx], m.Groups[gIdx].Value);
              }
            mIdx++;
          }
        }
    }
}
 
Matches Found:
[0][0] = testing/testing1/whitebox-testing-l4.html
[0][1] = testing/testing1
[0][2] = whitebox-testing
[0][3] = 4

Open in new window

0
 
ahoffmannCommented:
@"^(.*?)/([^/]+)-l(\d+).html"
0
 
uvalsAuthor Commented:
This is the solution for query
@"^(.*)/([^/]+)-l([0-9]+).html"

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.