M
M
MrKrot2016-10-14 02:29:53
Perl
MrKrot, 2016-10-14 02:29:53

Is it possible through a regular expression or some function to escape the characters after \ into the corresponding special characters?

The user enters a string containing non-escaped special characters (i.e. the string will contain substrings '\n', '\t', etc.)
I need to replace these substrings with the corresponding special characters, i.e. "\n", "\ t", etc.
Is there any function to do this? Or any one regex that implements this?
So far, I have in my mind only for each character to prescribe the corresponding regular expression, but this is a bug :( Like
this:

$1 =~ s/\\t/\t/gs;
$1 =~ s/\\n/\n/gs;
...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question