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 expressions groups

regular expressions groups

Scheduled Pinned Locked Moved C#
regexhelpquestion
3 Posts 3 Posters 0 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.
  • B Offline
    B Offline
    benams
    wrote on last edited by
    #1

    hi, I want to use regular expressions for analyzing a url, but I can't get the regex groups as I would expect them to be. My regular expression is: @"member/filter(.*)(/.+)*" The strings to match: 1) "member/filter-one" 2) "member/filter-two/option" 3) "member/filter-three/option/option" I expect to get the following groups: 1) member/filter-one, /filter-one 2) member/filter-two/option, /filter-two, /option 3) member/filter-three/option/option, /filter-three, /option(with 2 captures) I get the result for the first string, but fore the 2 others I get: 2) member/filter-two/option, /filter-two/option, empty string 3) member/filter-three/option/option, /filter-three/option/option, empty string What can be the issue?

    OriginalGriffO P 2 Replies Last reply
    0
    • B benams

      hi, I want to use regular expressions for analyzing a url, but I can't get the regex groups as I would expect them to be. My regular expression is: @"member/filter(.*)(/.+)*" The strings to match: 1) "member/filter-one" 2) "member/filter-two/option" 3) "member/filter-three/option/option" I expect to get the following groups: 1) member/filter-one, /filter-one 2) member/filter-two/option, /filter-two, /option 3) member/filter-three/option/option, /filter-three, /option(with 2 captures) I get the result for the first string, but fore the 2 others I get: 2) member/filter-two/option, /filter-two/option, empty string 3) member/filter-three/option/option, /filter-three/option/option, empty string What can be the issue?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      We do have a Regular expressions forum[^] - you should use that in future. But, it's a Sunday, and I'm feeling generous! :laugh: If you name your groups instead of using anonymous groups it becomes clearer what the problem is:

      member/filter(?.*)(?<Option>/[^/]+)*

      Shows that all of the matches are in the Prefix group: nothing gets as far as the Option group because the "any character, repeated" clause in the prefix swallows the option text as well. Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • B benams

        hi, I want to use regular expressions for analyzing a url, but I can't get the regex groups as I would expect them to be. My regular expression is: @"member/filter(.*)(/.+)*" The strings to match: 1) "member/filter-one" 2) "member/filter-two/option" 3) "member/filter-three/option/option" I expect to get the following groups: 1) member/filter-one, /filter-one 2) member/filter-two/option, /filter-two, /option 3) member/filter-three/option/option, /filter-three, /option(with 2 captures) I get the result for the first string, but fore the 2 others I get: 2) member/filter-two/option, /filter-two/option, empty string 3) member/filter-three/option/option, /filter-three/option/option, empty string What can be the issue?

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I second using the correct forum in the future.

        benams wrote:

        (/.+)*

        I've never gotten that sort of thing to work, so I expect it won't. Try @"member/filter([^/]*)/([^/]*)/([^/]*)" (And I like to name my groups too.)

        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