Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. regular expression problem

regular expression problem

Scheduled Pinned Locked Moved C#
regexhelptutorialquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mahraja
    wrote on last edited by
    #1

    Hi The pattern is sth like this: ^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$ and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused:

    I S 2 Replies Last reply
    0
    • M mahraja

      Hi The pattern is sth like this: ^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$ and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused:

      I Offline
      I Offline
      Igor Velikorossov
      wrote on last edited by
      #2

      A good starting point would be MSDN help ;) That section is extensive and pretty well written. Let's start with a simpler pattern. Once you get it working you can make it more complex. Suppose your pattern is smth like the following: (?<var1>\w+) "var1" is the name of your capture

      Regex r = new Regex(patter<, RegexOptions> );
      MatchCollection mc = r.Matches(your_text_to_match);
      if (mc.Count > 0)
      {
      // iterate though the collection
      // get the value with: mc[i].Groups["var1"].Value;
      }

      Well, something along these lines anyway, I'm typing it from the memory, can't check the syntax on the home pc.

      M 1 Reply Last reply
      0
      • I Igor Velikorossov

        A good starting point would be MSDN help ;) That section is extensive and pretty well written. Let's start with a simpler pattern. Once you get it working you can make it more complex. Suppose your pattern is smth like the following: (?<var1>\w+) "var1" is the name of your capture

        Regex r = new Regex(patter<, RegexOptions> );
        MatchCollection mc = r.Matches(your_text_to_match);
        if (mc.Count > 0)
        {
        // iterate though the collection
        // get the value with: mc[i].Groups["var1"].Value;
        }

        Well, something along these lines anyway, I'm typing it from the memory, can't check the syntax on the home pc.

        M Offline
        M Offline
        mahraja
        wrote on last edited by
        #3

        // get the value with: mc[i].Groups["var1"].Value; Thanks a lot, that was so useful :rose:

        modified on Wednesday, June 25, 2008 1:50 PM

        1 Reply Last reply
        0
        • M mahraja

          Hi The pattern is sth like this: ^-?((?<X>[0-9]{0,8})/(?<Y>[0-9]{0,15})|(?<X>[0-9]{0,8}))\*?$ and I want to have the variables in their named groups as following X=... Y=... I don't know how to use MatchCollection, CaptureCollection ,etc. Can anyone help me? :confused:

          S Offline
          S Offline
          SomeGuyThatIsMe
          wrote on last edited by
          #4

          another site that has helped me a lot in the past is http://www.regular-expression.info/[^] they even have a tool that you can use to quickly test your regex's

          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups