JavaScript中的另一个硬正则表达式:
我有这个字符串:
<td style="padding:0 2%">{% for product in products.pos01 %}
<table class="box-item" item-editable="" style="float:left;padding-bottom:10px; width:32%;border-spacing: 0px; border: 0px; border-collapse: collapse;"><tr><td style=" padding:10px 5px; vertical-align:top ">
<a href="**|product.url|**" class="button view-deal" style="padding:8px 10px; background-color: #fc5d26; text-decoration:none; display:inline-block; text-align:center; color:#fff; font-size:12px;margin:0px; line-height:140%;text-transform:uppercase">view deal</a></div></td></tr></table>{% if (loop.index0-2) is divisibleby 3 %}</td></tr><tr>
<td style="padding:0 2%">{% endif %}{% endfor %}
</td>
我正在尝试从字符串{%for ...%}和{%endfor%}的任何循环中获取内容
我已经尝试过,但无法
/({%for(!?%})+%})((!? endfor)*){%endfor%} / gm
但是没用
试试这个正则表达式:
{% for [^\0]+?{% endfor %}
解释:
{% for # search for text `{% for `
[^\0]+? # while not input's end
{% endfor %} # search for the next `{% endfor %}`
或者,如果您要分组:
{% (for [^\0]+?)%}([^\0]+?){% endfor %}
希望能帮助到你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句