Community
    • Login

    Find and replace except if string contains charecter

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 284 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.
    • Pinto IslamP
      Pinto Islam
      last edited by

      I have many documents where I need to “fix” html codes.

      When the files were created, some were create using POST[variable] and some were created POST[“variable”'] tags.

      I need to convert the POST[variable] tags with POST[“variable”] to standardize the documents and leave the POST[“variable”] tags alone

      If I use RegEx POST[(.+)] it finds all instances of POST[] entries (ones without the double quotes and ones withe the double quotes.

      Is there a RegEx that will tell it to only find the POST[variable] and to ignore the ones with POST[“variable”]?

      Hope this makes sense and someone can assist.
      Thanks in advance.

      CoisesC PeterJonesP 2 Replies Last reply Reply Quote 1
      • CoisesC
        Coises @Pinto Islam
        last edited by Coises

        @Pinto-Islam said in Find and replace except if string contains charecter:

        I need to convert the POST[variable] tags with POST[“variable”] to standardize the documents and leave the POST[“variable”] tags alone

        If I use RegEx POST[(.+)] it finds all instances of POST[] entries (ones without the double quotes and ones withe the double quotes.

        Try:
        Find what : POST\[([^"\]]++)\]
        Replace with : POST["\1"]

        Pinto IslamP 1 Reply Last reply Reply Quote 2
        • Mark OlsonM
          Mark Olson
          last edited by

          Coises’ proposal should work.

          If his solution isn’t quite what you’re looking for, I would probably start by amending the Find what to
          POST\s*\[\s*([^\s\]'"]+)\s*\]
          and leave the Replace with as is.
          Mine is a bit more resilient to corner cases and converts

          POST [ foo ]
          POST[bar]
          POST [
             baz_quz
          ]
          POST [$f89 ]
          POST["bar"]
          POST [ "foo" ]
          POST[ 'bar' ]
          

          to

          POST["foo"]
          POST["bar"]
          POST["baz_quz"]
          POST["$f89"]
          POST["bar"]
          POST [ "foo" ]
          POST[ 'bar' ]
          
          1 Reply Last reply Reply Quote 1
          • PeterJonesP
            PeterJones @Pinto Islam
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • Pinto IslamP
              Pinto Islam @Coises
              last edited by

              @Coises
              This worked perfect. After I posted, I was doing similar steps, but turns out I put the () in the wrong place and wasn’t getting the right result. Appreciate your help.

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