Split regular expression in

Posted on 2008-11-11
Last Modified: 2012-05-05
i need to split the regular expression @"^(\S*)/([^/]+)-l(\d+).html" in
Example url is testing/testing1/whitebox-testing-l4.html
I need Group[1] = testing/testing1
Group[2] = whitebox-testing
Group[3] = 4
Question by:uvals
    LVL 27

    Expert Comment


    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);
    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

    LVL 51

    Expert Comment

    LVL 2

    Author Comment

    This is the solution for query

    Open in new window

    LVL 1

    Accepted Solution

    PAQed with points refunded (125)

    EE Admin

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now