【发布时间】:2020-10-07 17:57:06
【问题描述】:
我有一个名为note_text 的textearea,一个名为note_preview 的div 和这个函数:
function fence_math(text) {
return text
.replace(new RegExp('\\\((.*?)\\\)', 'g'), '`memviv-math $1`')
.replace(new RegExp('\\\[(.*?)\\\]', 'g'), '`memviv-equation $1`');
}
如果我运行这个:
note_preview.innerHTML = fence_math(note_text.value);
当note_text 包含时
\(a *b* c\)
我明白了
<div id="note_preview">\`memviv-math a *b* c\`</div>
为什么重音符号前有反斜杠?我本来期望的:
<div id="note_preview">`memviv-math a *b* c`</div>
我该怎么做才能得到正确的结果?
【问题讨论】:
-
可能是因为你正在序列化一个字符串,而你不能在一个字符串中开始另一个字符串?
-
你能帮我解决它吗?我不明白为什么重音不被视为常规字符。
标签: javascript html regex