Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何仅使用正则表达式替换HTML组件_Javascript_Regex_String_Replace - Fatal编程技术网

Javascript 如何仅使用正则表达式替换HTML组件

Javascript 如何仅使用正则表达式替换HTML组件,javascript,regex,string,replace,Javascript,Regex,String,Replace,我目前正在编写一些服务器端代码来解析HTML。我有以下html字符串: <div class="rte-style-maintainer rte-pre-wrap" style="white-space: pre-wrap; font-size: small; >This is a test for link {<a spellcheck="false" destination="rte:bind" data-destination="rte:bind">ABCD 156

我目前正在编写一些服务器端代码来解析HTML。我有以下html字符串:

<div class="rte-style-maintainer rte-pre-wrap" style="white-space: pre-wrap; font-size: small; >This is a test for link {<a spellcheck="false" destination="rte:bind" data-destination="rte:bind">ABCD 156782053 </a>}</div>

首先,您的HTML语法是错误的。缺少一些结束语

无论如何,这个表达式的语法是:

/{(.*?)}/g

以下是测试链接:

由于缺少结束引号,您的HTML无效。第二,如果你能帮忙的话。关于
{}
区域的特殊性,具体是什么?换句话说,这是您需要解析的唯一字符串,还是可以采用任何格式?
{}
是否可以包含任意嵌套的HTML结构?需要更详细的信息,请展示您解决此问题的尝试。谢谢。如果你还没有考虑过的话,有一些轻量级的js库内置了对模板的支持,比如下划线或胡子。
/{(.*?)}/g