Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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_Jquery_Regex - Fatal编程技术网

javascript正则表达式到html

javascript正则表达式到html,javascript,jquery,regex,Javascript,Jquery,Regex,我有一些html内容 <p>{{Specifications}}</p> <p>some content down here</p> <p>{{/Specifications}}</p> <p>{{Photos}}</p> <h2>some content down here</h2> <p>some content down here</p> <

我有一些html内容

<p>{{Specifications}}</p>
<p>some content down here</p>
<p>{{/Specifications}}</p>

<p>{{Photos}}</p>
<h2>some content down here</h2>
<p>some content down here</p>
<p>some content down here</p>
...
<p>{{/Photos}}</p>
通过Jquery,我想得到每个集合的数组,返回两个独立变量中的{*}值和包含的html,这样我就可以将它放入一些div等中,并动态地将它转换为产品页面的选项卡


一旦我让正则表达式将其放入数组中,我就可以将其放入html等中,这只是我正在努力解决的正则表达式:p

答案是不要使用正则表达式

因为您已经在使用jquery,它使用sizzle从dom中选择元素,或者使用css选择器从一些html中选择元素

既然你可以控制加价,你就可以

<p>{{Photos}}</p>
<h2>some content down here</h2>
<p>some content down here</p>
<p>some content down here</p>
...
<p>{{/Photos}}</p>

然后使用jQuery删除“.section”标记,您就有了所需的标记,您还可以删除{{*}

标记如果它们仅用于划分节,您可以使用html打开和关闭标记,与其解析用于打开和关闭节的其他标记,不如先对其进行正确格式化。

如果您可以控制原始html,为什么不首先对其进行正确格式化?可以使用section标记或使用css类标记标题p标记…使用正则表达式解析HTML?我讨厌做那件事。那html是一个小胡子模板吗?哈哈,因为我们正在使用一个商店cms,它让用户能够为一个产品编辑1块文本,我正试图让客户能够通过编辑器快速、轻松地添加附加信息的标签,而不必知道如何编码;您可以将类添加到标记中吗?这样,您可以设置

,然后使用jQuery选择$'p.tabHeading'。好的,是的,我可以添加类。。。但这又引出了另一个问题。。。例如,我需要该类元素后面的内容作为将进入选项卡的内容,并对每个选项卡标题和后面的内容执行该操作。。。

<div class="section" data-section-name="photos">
    <p class="section-tag start">{{Photos}}</p>
    <h2>some content down here</h2>
    <p>some content down here</p>
    <p>some content down here</p>
    ...
    <p class="section-tag end">{{/Photos}}</p>
</div>
$('div.section[data-section-name="' + someVar + '"]);