如何排除具有特定属性的块内的正则表达式匹配项?
How can I exclude regex matches inside blocks with a certain attribute?
我正在尝试匹配所有标签,但文本区域内具有 "data-do-not-match-this='true'" 属性的标签除外。鉴于我有这个测试字符串:
<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}}
到目前为止我有这个正则表达式:
(?<!data\-do\-not\-match\-this="true">)({{.*?}})
正则表达式错误地匹配了 {{four}}、{{eight}}、{{nine}} 和 {{ten}}。如何修复正则表达式以排除我不想匹配的标签?
这是我的 Rubular:
这是一种可能性:
<textarea[^>]+data-match-this="[^"]+"[^>]*>.*?<\/textarea>
很难……
(?:<textarea data-do-not-match-this="true">.+?<\/textarea>.*?)?({{.*?}})
我正在尝试匹配所有标签,但文本区域内具有 "data-do-not-match-this='true'" 属性的标签除外。鉴于我有这个测试字符串:
<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}}
到目前为止我有这个正则表达式:
(?<!data\-do\-not\-match\-this="true">)({{.*?}})
正则表达式错误地匹配了 {{four}}、{{eight}}、{{nine}} 和 {{ten}}。如何修复正则表达式以排除我不想匹配的标签?
这是我的 Rubular:
这是一种可能性:
<textarea[^>]+data-match-this="[^"]+"[^>]*>.*?<\/textarea>
很难……
(?:<textarea data-do-not-match-this="true">.+?<\/textarea>.*?)?({{.*?}})