我想要一些正则表达式的帮助,因为我不太熟悉。到目前为止,我已经创建了以下正则表达式:
/\b(?<![\#\-\/\>])literal(?![\<\'\"])\b/i断言在单词边界处的位置(^\w\\w$溶胶\w\w) 负查找(?) 断言下面的Regex不匹配 匹配下面列表中的单个字符#-/>匹配字符#字面上(不区分大小写)
我想在这个匹配规则中添加两个例外。1)如果">“前面有"p”(例如,一个<p>开始标记),则只匹配文字。2)此外,只有当<被/p (例如,</p>结束标记)折叠时,才应该匹配文字。如何才能做到这一点?
例:只有粗体的才能匹配。
<p>
**Literal** in computer science is a
<a href='http://www.google.com/something/literal#literal'>literal</a>
for representing a fixed value in source code. Almost all programming
<a href='http://www.google.com/something/else-literal#literal'>languages</a>
have notations for atomic values such as integers, floating-point
numbers, and strings, and usually for booleans and characters; some
also have notations for elements of enumerated types and compound
values such as arrays, records, and objects. An anonymous function
is a **literal** for the function type which is **LITERAL**
</p>我知道我有些过于复杂的事情,但情况本身很复杂,我想我没有别的办法了。
发布于 2016-10-02 17:17:52
如果您正在搜索的文本只是与一些<a>标记混合的文本,那么您可以简化<和>部分,并给出一个不应该后面跟着的特定字符串:</a>。
/\b(?<![-#\/])literal(?!<\/a>)\b/ihttps://stackoverflow.com/questions/39818681
复制相似问题