How to unescape?
-
@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”)?
-
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 -
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! :)
-
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 -
"\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(\"))
-
a little correction to previous post: there must be \\t instead of \t in the first field
-
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
-
@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.
-
@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:
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. :-)
-
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
-
-
@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. -
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
orlicense.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