Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Regular Expressions

    General Discussion
    3
    8
    2674
    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.
    • Victor Fatal
      Victor Fatal last edited by

      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?

      Scott Sumner 1 Reply Last reply Reply Quote 0
      • Terry R
        Terry R last edited by Terry R

        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

        Victor Fatal 1 Reply Last reply Reply Quote 3
        • Scott Sumner
          Scott Sumner @Victor Fatal last edited by

          @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
          • Victor Fatal
            Victor Fatal last edited by

            @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
            • Victor Fatal
              Victor Fatal @Terry R last edited by Victor Fatal

              @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
              • Terry R
                Terry R last edited by

                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
                • Scott Sumner
                  Scott Sumner last edited by

                  @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
                  • Terry R
                    Terry R last edited by

                    @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
                    • First post
                      Last post
                    Copyright © 2014 NodeBB Forums | Contributors