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. Regular Expressions
  4. Even Expresso couldn't help me with this RegEx - Can You?

Even Expresso couldn't help me with this RegEx - Can You?

Scheduled Pinned Locked Moved Regular Expressions
helpregexquestion
9 Posts 4 Posters 39 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.
  • S Offline
    S Offline
    Sonhospa
    wrote on last edited by
    #1

    Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?

    Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)

    is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.

    ' Sample
    [Track]
    Latitude=N047° 25' 53.4256"
    Longitude=W122° 18' 28.7933"
    Altitude=+000432.00

    [Options]
    Titles=False
    Sound=True
    Pause=False

    Thank you very much in advance, Michael

    L P 2 Replies Last reply
    0
    • S Sonhospa

      Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?

      Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)

      is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.

      ' Sample
      [Track]
      Latitude=N047° 25' 53.4256"
      Longitude=W122° 18' 28.7933"
      Altitude=+000432.00

      [Options]
      Titles=False
      Sound=True
      Pause=False

      Thank you very much in advance, Michael

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Michael, I guess something is wrong in your post, I see only one double quote, and no MultiLine option. You probably have a conflict with the HTML monster. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      S 1 Reply Last reply
      0
      • L Luc Pattyn

        Michael, I guess something is wrong in your post, I see only one double quote, and no MultiLine option. You probably have a conflict with the HTML monster. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        S Offline
        S Offline
        Sonhospa
        wrote on last edited by
        #3

        Happy day :-D! I could resolve a part of my regex task in Expresso. For the record and other users: Obviously ".*" for "any character / any number of repetitions" is not good enough to capture a CRLF! Trying to capture it with \r wasn't the right thing either, it took "\r\n" to match the group together with the first line! Here's the current status of the regex:

        \[(?<Grp>.*)\]\r\n(?<Keyword>\w+)\s*=\s*(?<Value>.*)\r

        The ultimate question would now be: Of course the first key-value-pair after the group header isn't enough. How can I include its repetitions into my match now? :confused: @ Luc: Thanks for the hint. I guess it was more a matter with my own attention monster ;) that I had here... @ Admin: Pls excuse me double-posting with the VB forum. This new forum obviously isn't too known yet, so that I had more forwarding answers there before being told to shift my post here...

        L 1 Reply Last reply
        0
        • S Sonhospa

          Happy day :-D! I could resolve a part of my regex task in Expresso. For the record and other users: Obviously ".*" for "any character / any number of repetitions" is not good enough to capture a CRLF! Trying to capture it with \r wasn't the right thing either, it took "\r\n" to match the group together with the first line! Here's the current status of the regex:

          \[(?<Grp>.*)\]\r\n(?<Keyword>\w+)\s*=\s*(?<Value>.*)\r

          The ultimate question would now be: Of course the first key-value-pair after the group header isn't enough. How can I include its repetitions into my match now? :confused: @ Luc: Thanks for the hint. I guess it was more a matter with my own attention monster ;) that I had here... @ Admin: Pls excuse me double-posting with the VB forum. This new forum obviously isn't too known yet, so that I had more forwarding answers there before being told to shift my post here...

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Michael, I'm not really a regex expert, but I would tackle your problem with two regex and two foreach; the first regex would locate groups, the second would parse the key=value pairs within a group. I've never seen this done with a single regex. BTW: I don't like your \r\n stuff at all. One normally uses the symbols for start-of-line (^) and end-of-lin ($)e, avoiding problems with matching things on the first line and last line (your input may or may not end on \r or \r\n). FYI: I have some similar regex stuff in my article CP Vanity[^] which scrapes some of the CodeProject web pages. Similiar meaning two regexes, two foreach loops. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          • S Sonhospa

            Hi all, it must be a small problem that drives me crazy here... From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?

            Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)

            is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.

            ' Sample
            [Track]
            Latitude=N047° 25' 53.4256"
            Longitude=W122° 18' 28.7933"
            Altitude=+000432.00

            [Options]
            Titles=False
            Sound=True
            Pause=False

            Thank you very much in advance, Michael

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

            Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].

            L A 2 Replies Last reply
            0
            • P PIEBALDconsult

              Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              the OP started with a "Dim", in VB there is no escape mechanism AFAIK. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              P 1 Reply Last reply
              0
              • L Luc Pattyn

                the OP started with a "Dim", in VB there is no escape mechanism AFAIK. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

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

                :doh: I need sleep. This working for eight hours a day sucks, why do people do it?

                A 1 Reply Last reply
                0
                • P PIEBALDconsult

                  :doh: I need sleep. This working for eight hours a day sucks, why do people do it?

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #8

                  (fun)?$

                  [Forum Guidelines]

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Don't you need to double (escape) the backslashes? This is part of why I wrote my RegexTester[^].

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #9

                    Making tools to help with regular expressions must be fun, because I made one too. Looks kinda like yours. :)

                    [Forum Guidelines]

                    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