• Login
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.
  • P
    Pinto Islam
    last edited by Jan 19, 2024, 9:07 PM

    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.

    C P 2 Replies Last reply Jan 19, 2024, 9:44 PM Reply Quote 1
    • C
      Coises @Pinto Islam
      last edited by Coises Jan 19, 2024, 9:46 PM Jan 19, 2024, 9:44 PM

      @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"]

      P 1 Reply Last reply Jan 19, 2024, 10:15 PM Reply Quote 2
      • M
        Mark Olson
        last edited by Jan 19, 2024, 10:00 PM

        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
        • P
          PeterJones @Pinto Islam
          last edited by Jan 19, 2024, 10:08 PM

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • P
            Pinto Islam @Coises
            last edited by Jan 19, 2024, 10:15 PM

            @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
            2 out of 5
            • First post
              2/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors