Community
    • Login

    How to unescape?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 6 Posters 13.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.
    • Valerjans VinogradovsV
      Valerjans Vinogradovs @Claudia Frank
      last edited by Valerjans Vinogradovs

      @Claudia-Frank, How in find/replace to unescape all escapes (for example: \" … \r\n … \t …) in the whole text by one command (by one click on the button “Replace All”)?

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @Valerjans Vinogradovs
        last edited by

        @Valerjans-Vinogradovs

        first post ("\r\n\t…)
        next post (for example: " … \r\n … \t …)

        I assume the real text is even different, so how should we know what your text really looks like to give you an advice?? Because of that lack of information I only can give
        you an general answer.

        If there is a pattern you might be able to use Extended search mode, if the pattern
        is different try to find a regular expression which fits all.

        Cheers
        Claudia

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

          Is the OP asking how to replace two character sequences (for example, “” followed by “r”) in his editor window with their corresponding single character value (13 or hex 0D in the example)? Just a guess as I can’t really tell.

          This speaks to a general complaint about a lot of posters on this community: Not enough information is given to BEST solve a problem. People will post, “How can I do XXX?” when a much better question is “I think I need to do XXX because I need to achieve <insert detailed explanation here> – how can I best do this?”. The experts here, who could certainly answer the XXX question, might answer it in a totally different way with the benefit of background info that gives the poster a much better push towards solving their real problem in a efficient, clean and often elegant way! :)

          1 Reply Last reply Reply Quote 1
          • Claudia FrankC
            Claudia Frank
            last edited by

            Is the OP asking how to replace two character sequences (for example, “” followed by “r”) in his editor window with their corresponding single character value (13 or hex 0D in the example)? Just a guess as I can’t really tell.

            Didn’t thought about this - thought OP maybe has some code with literals \t …
            and the compiler complaint about it but …

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • Valerjans VinogradovsV
              Valerjans Vinogradovs
              last edited by Valerjans Vinogradovs

              "\r\n\t …

              as well as

              \" … \r\n … \t …

              can be unescaped by find/replace by one click on the button “Replace All” when:

              in the first field (Find what) is entered: (\\r\\n)|(\t)|(\\\")

              and in second field (Replace with) is entered: (?1(\r\n))(?2(\t))(?3(\"))

              1 Reply Last reply Reply Quote 0
              • Valerjans VinogradovsV
                Valerjans Vinogradovs
                last edited by

                a little correction to previous post: there must be \\t instead of \t in the first field

                1 Reply Last reply Reply Quote 0
                • Gioacchino PiazzollaG
                  Gioacchino Piazzolla
                  last edited by

                  hi i use this website to do it: https://www.freeformatter.com/json-escape.html

                  You can escape/unscape a string with this.

                  I’m here to ask if there is a plugin that does the same thing

                  Alan KilbornA 2 Replies Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Gioacchino Piazzolla
                    last edited by

                    @Gioacchino-Piazzolla said in How to unescape?:

                    here to ask if there is a plugin that does the same thing

                    Probably nobody is going to the trouble to create a plugin to do something that a replace-operation recorded into a macro can easily do.

                    Of course, maybe that functionality is part of a plugin that does more than that (justifying the plugin’s existence); I don’t know.

                    1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @Gioacchino Piazzolla
                      last edited by Alan Kilborn

                      @Gioacchino-Piazzolla said in How to unescape?:

                      hi i use this website to do it: https://www.freeformatter.com/json-escape.html

                      So from what I see of that web site, recording the following Replace All macro will do the same conversion when later run on some selected text:

                      e17a6bd8-6f0f-45cc-9096-5c7250136d1f-image.png

                      Start macro recording after setting up the Replace dialog as shown, press the button indicated with the red dot, then stop macro recording and save the macro with a descriptive name.

                      Here are the find/repl fields as text:

                      find: (?-i)(\x08)|(\x0c)|(\n)|(\r)|(\t)|(")|(\\)
                      repl: (?1\\b)(?2\\f)(?3\\n)(?4\\r)(?5\\t)(?6\\")(?7\\\\)

                      Note that \x08 could be replaced with \a and \x0c could be replaced with \f. As you like…

                      Edit: I just noticed that the subject of this thread was “unescaping” and my replace macro does “escaping”. Oh, well, the unescaping version is left as an exercise for the reader, using what I provided as the model. :-)

                      1 Reply Last reply Reply Quote 1
                      • guy038G
                        guy038
                        last edited by

                        Hello @gioacchino-piazzolla, @alan-kilborn and All,

                        If you work with Windows files ( line endings = \r\n ) here are two regex S/R :

                        • The first one Escape the usual characters :

                          • SEARCH \r\n(*SKIP)(*F)|(\a)|(\x08)|(\f)|(\n)|(\r)|(\t)|(")|(')|(\\)

                          • REPLACE \\(?1a)(?2x08)(?3f)(?4n)(?5r)(?6t)(?7")(?8')(?9\\)

                        • The second one UNnescape the usual characters :

                          • SEARCH (?-i)\\(?:(a)|(x08)|(f)|(n)|(r)|(t)|(")|(')|(\\))

                          • REPLACE (?1\a)(?2\x08)(?3\f)(?4\n)(?5\r)(?6\t)(?7")(?8')(?9\\)


                        Now, Alan, a little mistake ! \a = \x07 and [\b] = \x08.

                        Note that \b must be in a character class as \b, outside a character class is an assertion defining the empty location between, either :

                        • A Word character and a Non word char

                        • A Non word character and a Word char

                        Best regards,

                        guy038

                        Alan KilbornA 1 Reply Last reply Reply Quote 1
                        • Alan KilbornA
                          Alan Kilborn @guy038
                          last edited by

                          @guy038 said in How to unescape?:

                          \a = \x07

                          Ah yes, when I said \x08 it was a repetitive typo. :-(
                          Meaning once I had the first mistake, I stopped thinking about it and just carried it on. :-( :-(

                          More interesting (and getting the “heat” off of me…) is your use of \r\n(*SKIP)(*F) which appears to be intended to not replace any \r\n pairs in the data. I don’t know that this is a valid thing to do. The website the “recent” OP pointed to doesn’t do that. Similar for the ' character.

                          1 Reply Last reply Reply Quote 1
                          • guy038G
                            guy038
                            last edited by guy038

                            Hi, @gioacchino-piazzolla, @alan-kilborn and All,

                            I agree that I could have written the first regex S/R to Escape these special characters as :

                            SEARCH (\a)|(\x08)|(\f)|(\n)|(\r)|(\t)|(")|(')|(\\)

                            REPLACE \\(?1a)(?2x08)(?3f)(?4n)(?5r)(?6t)(?7")(?8')(?9\\)

                            But , in that case, any text is changed in a one-line text. Just give it a try with the change.log or license.txt file ! Don’t know if this syntax is expected by the OP ?


                            Now, I added the single quote character as I remember that the TextFX plugin can escape/unescape the ' character !

                            BR

                            guy038

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