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. regex.matches ?

regex.matches ?

Scheduled Pinned Locked Moved C#
regexhtmlcomquestion
7 Posts 2 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.
  • E Offline
    E Offline
    enginco
    wrote on last edited by
    #1

    hi everybody, I have a text like this:

    <img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >

    and I have pattern like this:

    pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+

    I wnat to get "src" block.

    foreach (Match submatch in Regex.Matches(pattern))
    {
    submatch.groups.... // It returns allways 2 groups
    }

    It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...

    I want to fly but I don't have wings

    L 2 Replies Last reply
    0
    • E enginco

      hi everybody, I have a text like this:

      <img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >

      and I have pattern like this:

      pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+

      I wnat to get "src" block.

      foreach (Match submatch in Regex.Matches(pattern))
      {
      submatch.groups.... // It returns allways 2 groups
      }

      It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...

      I want to fly but I don't have wings

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Set the ExplicitCapture flag when creating the Regex.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      E 1 Reply Last reply
      0
      • L leppie

        Set the ExplicitCapture flag when creating the Regex.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        E Offline
        E Offline
        enginco
        wrote on last edited by
        #3

        it has "RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture" interesting point is: if the text has " or ' it's working correctly ex 1: <img src="http://www.takvim.com.tr/i/spacer\_trans\_1x1.gif" width="10" height="1"> ex 2: <img src=http://www.takvim.com.tr/i/spacer\_trans\_1x1.gif width=10 height=1> ex 1: is working ex 2: doesn't work

        I want to fly but I don't have wings

        1 Reply Last reply
        0
        • E enginco

          hi everybody, I have a text like this:

          <img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >

          and I have pattern like this:

          pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+

          I wnat to get "src" block.

          foreach (Match submatch in Regex.Matches(pattern))
          {
          submatch.groups.... // It returns allways 2 groups
          }

          It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...

          I want to fly but I don't have wings

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          I think you grouping might be incorrect. Try do the isolated cases first, then combine them once they are working. Currently you have no idea if it is the regex that is incorrect or the way the grouping has been constructed (it may be that it only allows the define the grouping name once, in that case you need to wrap the grouping around all possible options).

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          E 1 Reply Last reply
          0
          • L leppie

            I think you grouping might be incorrect. Try do the isolated cases first, then combine them once they are working. Currently you have no idea if it is the regex that is incorrect or the way the grouping has been constructed (it may be that it only allows the define the grouping name once, in that case you need to wrap the grouping around all possible options).

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            E Offline
            E Offline
            enginco
            wrote on last edited by
            #5

            :sigh: I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases. It seperates to groups correctly. :confused: I'm confused...

            (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+

            may be ?<name> and ?<value> are problem. I don't know...

            I want to fly but I don't have wings

            L 1 Reply Last reply
            0
            • E enginco

              :sigh: I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases. It seperates to groups correctly. :confused: I'm confused...

              (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+

              may be ?<name> and ?<value> are problem. I don't know...

              I want to fly but I don't have wings

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              enginço wrote:

              I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.

              Then you probably did something wrong when copying the regex expression to code.

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              E 1 Reply Last reply
              0
              • L leppie

                enginço wrote:

                I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.

                Then you probably did something wrong when copying the regex expression to code.

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 4a out now (29 May 2008)

                E Offline
                E Offline
                enginco
                wrote on last edited by
                #7

                thanx for your reply, I found the problem | (?[^"'<> \s]*) | is wrong |(?\w[^"'<> \s]*)| is correct But both is OK on The Regex Coach program, in C# it's behave different. Infact I don't know how is working getting groupCollection. :) Anyway, it's solved. Thanx

                I want to fly but I don't have wings

                modified on Thursday, September 11, 2008 7:48 AM

                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