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. Correct Expression For 'Any Character Including Whitespace'

Correct Expression For 'Any Character Including Whitespace'

Scheduled Pinned Locked Moved Regular Expressions
regexquestion
7 Posts 3 Posters 8 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, I've been fighting with this for hours now, but don't get it to work. I want to strip out some information from an ini-file, which basically looks like this:

    [CameraDefinition.1]
    Title=Linke Seite
    Guid={0ae3f864-da10-4e5a-977c-b9bba47d6f7a}
    Description=Ansicht nach links
    Origin=Center

    It's a standard Windows text file, the sections are separated with two new lines (\r\n\r\n). My regex currently looks like this: "\[CameraDefinition\.(?\d+)\][.|\s]*Guid=(?\{[0-9A-F\-]*\})" While the first (CamNumber) and the last part (Guid) return correct results as 'partial match', the critical part seems to be the underlined expression for "everything between the top and the Guid", which might be several lines. I'd be happy if someone of you helps me solve this... Thank you in advance! Regards Mick

    L B S 3 Replies Last reply
    0
    • S Sonhospa

      Hi all, I've been fighting with this for hours now, but don't get it to work. I want to strip out some information from an ini-file, which basically looks like this:

      [CameraDefinition.1]
      Title=Linke Seite
      Guid={0ae3f864-da10-4e5a-977c-b9bba47d6f7a}
      Description=Ansicht nach links
      Origin=Center

      It's a standard Windows text file, the sections are separated with two new lines (\r\n\r\n). My regex currently looks like this: "\[CameraDefinition\.(?\d+)\][.|\s]*Guid=(?\{[0-9A-F\-]*\})" While the first (CamNumber) and the last part (Guid) return correct results as 'partial match', the critical part seems to be the underlined expression for "everything between the top and the Guid", which might be several lines. I'd be happy if someone of you helps me solve this... Thank you in advance! Regards Mick

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Probably easier just to read it line by line and look for the keyword you are interested in.

      S 1 Reply Last reply
      0
      • L Lost User

        Probably easier just to read it line by line and look for the keyword you are interested in.

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

        Hi Richard, thank you for your response. It's exactly what I did meanwhile... still I hope someone knows an answer, so that this seemingly simple task wouldn't annoy me again :-)

        L 1 Reply Last reply
        0
        • S Sonhospa

          Hi all, I've been fighting with this for hours now, but don't get it to work. I want to strip out some information from an ini-file, which basically looks like this:

          [CameraDefinition.1]
          Title=Linke Seite
          Guid={0ae3f864-da10-4e5a-977c-b9bba47d6f7a}
          Description=Ansicht nach links
          Origin=Center

          It's a standard Windows text file, the sections are separated with two new lines (\r\n\r\n). My regex currently looks like this: "\[CameraDefinition\.(?\d+)\][.|\s]*Guid=(?\{[0-9A-F\-]*\})" While the first (CamNumber) and the last part (Guid) return correct results as 'partial match', the critical part seems to be the underlined expression for "everything between the top and the Guid", which might be several lines. I'd be happy if someone of you helps me solve this... Thank you in advance! Regards Mick

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          The format of entries in an ini file is Key=Value. That is, get the position of the first = sign, the substring on the left is the key, the substring on the right is the value.

          1 Reply Last reply
          0
          • S Sonhospa

            Hi Richard, thank you for your response. It's exactly what I did meanwhile... still I hope someone knows an answer, so that this seemingly simple task wouldn't annoy me again :-)

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            It's not clear exactly what you are trying to extract. But either way, my suggestion is much easier.

            1 Reply Last reply
            0
            • S Sonhospa

              Hi all, I've been fighting with this for hours now, but don't get it to work. I want to strip out some information from an ini-file, which basically looks like this:

              [CameraDefinition.1]
              Title=Linke Seite
              Guid={0ae3f864-da10-4e5a-977c-b9bba47d6f7a}
              Description=Ansicht nach links
              Origin=Center

              It's a standard Windows text file, the sections are separated with two new lines (\r\n\r\n). My regex currently looks like this: "\[CameraDefinition\.(?\d+)\][.|\s]*Guid=(?\{[0-9A-F\-]*\})" While the first (CamNumber) and the last part (Guid) return correct results as 'partial match', the critical part seems to be the underlined expression for "everything between the top and the Guid", which might be several lines. I'd be happy if someone of you helps me solve this... Thank you in advance! Regards Mick

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

              Hello and thank you both! :thumbsup: In order to solve the regex issue, I successfully tried to read the first three lines of each block:

              \[CameraDefinition\.(?\d+)\]\r\nTitle\=(?.*)\r\nGuid\=(?<Guid>\{[0-9A-Fa-f\-]*\})</pre>Considering the results, this works well, is fast and gives me the title as an additional field. In case I recognize any errors, I'll go back to reading line by line and also consider your hint regarding general ini-file structure.

              Thank you again, and have a nice day! :)

              EDIT: Changing the critical middle part to the following helped...
              <pre>\[CameraDefinition\.(?<CamNumber>\d+)\]\r\n(.*\r\n)Guid\=(?<Guid>\{[0-9A-Fa-f\-]*\})\r\n{1,}</pre>This way I have the correct matches as well. But: Still no capture if there are more lines between the top line and the GUID definition.</x-turndown>

              L 1 Reply Last reply
              0
              • S Sonhospa

                Hello and thank you both! :thumbsup: In order to solve the regex issue, I successfully tried to read the first three lines of each block:

                \[CameraDefinition\.(?\d+)\]\r\nTitle\=(?.*)\r\nGuid\=(?<Guid>\{[0-9A-Fa-f\-]*\})</pre>Considering the results, this works well, is fast and gives me the title as an additional field. In case I recognize any errors, I'll go back to reading line by line and also consider your hint regarding general ini-file structure.

                Thank you again, and have a nice day! :)

                EDIT: Changing the critical middle part to the following helped...
                <pre>\[CameraDefinition\.(?<CamNumber>\d+)\]\r\n(.*\r\n)Guid\=(?<Guid>\{[0-9A-Fa-f\-]*\})\r\n{1,}</pre>This way I have the correct matches as well. But: Still no capture if there are more lines between the top line and the GUID definition.</x-turndown>

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Sonhospa wrote:

                no capture if there are more lines between ...

                Exactly why a regex is not the best way to do this.

                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