0

I have a function for replacing strings

function replaceLetters(str) {
    return str.replace('a\\\a', "!")
}
replaceLetters('a\a a\\a a\\\a')

As a result I get string like "aa ! a\a" but I need string like "a\a a\a !"

Can you please help me with this task?

  • 2
    Your input does not have triple literal backslashes - two backslashes together result in a single literal backslash, and a backslash before a non-escape character gets discarded by the parser. – CertainPerformance Mar 27 '20 at 21:09
  • If you want to have *triple* backslash, then you need a string literal with *six* backslashes: `"\\\\\\"` produces three bacckslashes because each needs to be escaped. – VLAZ Mar 27 '20 at 21:09
  • @CertainPerformance ok, I understood this, and what can you advise me? my main task is to get '!' instead of 'a\\\a' when I use six backslashes I get "aa a\a a\a" – Ihor Dubas Mar 27 '20 at 21:39

0 Answers0