• Login
Community
  • Login

Regular Expressions

Scheduled Pinned Locked Moved General Discussion
8 Posts 3 Posters 4.6k Views
Loading More Posts
  • 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.
  • V
    Victor Fatal
    last edited by Sep 5, 2018, 7:11 PM

    I have text files like that:

    true
    {
    true
    0.890000 0.195000 2000.000000
    }
    true
    {
    false
    0.000000
    }
    {
    version 0
    0.385000
    }
    {
    version 1
    diffuse= maps/Autumn.dds
    specular = Forest.dds
    }

    false
    0.003208
    “”
    1
    “FogLinear” "-212.500000 3450.000000 0.000000 0.301961 0.380392 0.415686 "
    false
    {
    version 1
    }

    I need find:
    {
    version 1
    diffuse= maps/Autumn.dds
    specular = Forest.dds
    }

    and
    {
    version 1
    }

    excluding:

    {
    version 0
    0.385000
    }

    And delete it. How can this be done?

    S 1 Reply Last reply Sep 5, 2018, 7:59 PM Reply Quote 0
    • T
      Terry R
      last edited by Terry R Sep 5, 2018, 7:53 PM Sep 5, 2018, 7:53 PM

      So if I read correctly you are searching for only the “version 1” sequence ending with the relevant “}”. Within version 1 is it ONLY with autumn.dds or is any text allowed within version 1?

      Terry

      V 1 Reply Last reply Sep 5, 2018, 10:03 PM Reply Quote 3
      • S
        Scott Sumner @Victor Fatal
        last edited by Sep 5, 2018, 7:59 PM

        @Victor-Fatal

        You have asked regular expression related questions here before…what regular expression replacement have you tried for your current problem? It’s always good to see what one is considering for a solution, even if it isn’t quite working.

        1 Reply Last reply Reply Quote 1
        • V
          Victor Fatal
          last edited by Sep 5, 2018, 9:39 PM

          @Terry-R said:

          So if I read correctly you are searching for only the “version 1” sequence ending with the relevant “}”. Within version 1 is it ONLY with autumn.dds or is any text allowed within version 1?

          Terry I need delete all this stuff:
          {
          version 1
          diffuse= maps/Autumn.dds
          specular = Forest.dds
          }

          From “{” to “}”, but exclude blocks which have “version 0” like this:
          {
          version 0
          0.385000
          }

          1 Reply Last reply Reply Quote 0
          • V
            Victor Fatal @Terry R
            last edited by Victor Fatal Sep 5, 2018, 10:03 PM Sep 5, 2018, 10:03 PM

            @Scott-Sumner said:

            @Victor-Fatal

            You have asked regular expression related questions here before…what regular expression replacement have you tried for your current problem? It’s always good to see what one is considering for a solution, even if it isn’t quite working.

            so far I have come to this search query request:
            version 1.*?[}]
            but I can not get the upper brace.

            1 Reply Last reply Reply Quote 0
            • T
              Terry R
              last edited by Sep 5, 2018, 11:42 PM

              Without further information all I can present is
              Find what: (?s)(\{\Rversion 1.+?version 1\R\})
              Replace with: leave this field empty

              This will capture ALL “version 1” sequences from opening { to closing }. Hopefully you can see where your regex might have failed and this one works and learn from that.

              Terry

              1 Reply Last reply Reply Quote 1
              • S
                Scott Sumner
                last edited by Sep 6, 2018, 12:07 PM

                @Terry-R said:

                (?s)({\Rversion 1.+?version 1\R})

                Hmmm…using the sample data provided, that seems to remove all this:

                {
                version 1
                diffuse= maps/Autumn.dds
                specular = Forest.dds
                }
                false
                0.003208
                “”
                1
                “FogLinear” "-212.500000 3450.000000 0.000000 0.301961 0.380392 0.415686 "
                false
                {
                version 1
                }
                

                …which seems like maybe removing too much?

                To follow what the OP said initially, I’d try:

                Find what zone: {\Rversion 1[^}]+\}
                Replace with zone: leave this empty
                Wrap around checkbox: as you like it
                Search mode: Regular expression
                Action: Press Replace / Replace All button

                Which leaves one with the following after replacement:

                true
                {
                true
                0.890000 0.195000 2000.000000
                }
                true
                {
                false
                0.000000
                }
                {
                version 0
                0.385000
                }
                
                false
                0.003208
                “”
                1
                “FogLinear” "-212.500000 3450.000000 0.000000 0.301961 0.380392 0.415686 "
                false
                

                Here’s an explanation of how the find works (replacement is merely with nothing):

                THE FIND EXPRESSION:

                {\Rversion 1[^}]+\}

                • [Match the character “{” literally][1 ] {
                • [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][2 ] \R
                • [Match the character string “version 1” literally (case sensitive)][1 ] version 1
                • [Match any character that is NOT a “}”][1 ] [^}]+
                  • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][3 ] +
                • [Match the character “}” literally][4 ] \}

                Created with RegexBuddy

                [1 ]: http://www.regular-expressions.info/characters.html
                [2 ]: http://www.regular-expressions.info/nonprint.html
                [3 ]: http://www.regular-expressions.info/repeat.html
                [4 ]: http://www.regular-expressions.info/characters.html#special

                1 Reply Last reply Reply Quote 1
                • T
                  Terry R
                  last edited by Sep 6, 2018, 7:38 PM

                  @Scott-Sumner, you may be right. I had originally interpreted it the way I had, but reading again, I’m heading your direction now.

                  It all goes back to getting “good” and “clear” information. I was looking at them like html tags, so an opening and closing “version 1” pair.

                  The OP will have choices now and when they try each option they can make the decision for themselves…

                  Terry

                  1 Reply Last reply Reply Quote 2
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors