How to make javascript ignore escape ( \ ) character?
But the escape tag "\" disappears, but I need it there, what should I do?
You need to escape the backslash, i.e., use \\
instead of just \
:
"[math]k: \\frac{(x+20)^{2}}{256}+\\frac{(y-15)^{2}}{81}=1[/math]"
^ ^
Escape the escape character, like \\a
.
You can use tagged template literals
var str = (s => s.raw)`[math]k: \frac{(x+20)^{2}}{256}+\frac{(y-15)^{2}}{81}=1[/math]`[0]
The anonymous arrow function will serve as tag and s.raw
contains the original input