[英]How can I exclude regex matches inside blocks with a certain attribute?
I am trying to match all tags except for tags inside textareas that have the "data-do-not-match-this='true'" attribute.我正在尝试匹配除 textareas 中具有“data-do-not-match-this='true'”属性的标签之外的所有标签。 Given I have this test string:鉴于我有这个测试字符串:
<textarea>{{one}}{{two}}</textarea>
<textarea data-do-not-match-this="true">{{three}}{{four}}</textarea>
<textarea>
{{five}}
{{six}}{{seven}}
</textarea>
<textarea data-do-not-match-this="true">
{{eight}}
{{nine}}{{ten}}
</textarea>
{{eleven}}{{twelve}}
I have this regex so far:到目前为止我有这个正则表达式:
(?<!data\-do\-not\-match\-this="true">)({{.*?}})
The regex incorrectly matches {{four}}, {{eight}}, {{nine}}, and {{ten}}.正则表达式错误地匹配 {{four}}、{{eight}}、{{nine}} 和 {{ten}}。 How can I fix the regex to exclude tags I do not want to match?如何修复正则表达式以排除我不想匹配的标签?
This is my Rubular:这是我的rubular:
https://rubular.com/r/TfjuwRd8dSjFJX https://rubular.com/r/TfjuwRd8dSjFJX
It was hard…那个挺难…
(?:<textarea data-do-not-match-this="true">.+?<\/textarea>.*?)?({{.*?}})
https://rubular.com/r/32MFMtZ2Ms3lOX https://rubular.com/r/32MFMtZ2Ms3lOX
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.