Community
    • Login

    Find and replace except if string contains charecter

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 595 Views 2 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            PeterJones @Pinto Islam
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • Pinto IslamP Offline
              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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors