我想找到一个正则表达式来选择所有没有<p class="test_formal">
前面的行<span class="test_formal2">
<p class="test_formal"><span class="test_formal2">
我制作了一个正则表达式,但不太好。
(?s)\A(?!.*?(?<!\w)(<span class="test_formal2">)(?!\w)<p class="test_formal">).*
有人可以帮我一下吗?
答案1
这将匹配所有包含以下内容的行:
<span class="test_formal2">
或没有<p class="test_formal">
但<p class="test_formal">
随后<span class="test_formal2">
- Ctrl+F
- 找什么:
^(?:(?!<p class="test_formal">).)*<span class="test_formal2">.*$
- 检查环绕
- 检查正则表达式
- 取消选中
. matches newline
- Search in document
解释:
^ # beginning of line
(?: # start non capture group
(?! # negative lookahead, make sure we haven't
<p class="test_formal"> # literally
) # end lookahead
. # 1 any character
)* # end group, may appear 0 or more times
<span class="test_formal2"> # literally
.* # 0 or more any character
$ # end of line
鉴于:
<p class="test_formal">
<span class="test_formal2">
<p class="test_formal"><span class="test_formal2">
blah blah <p class="test_formal"><span class="test_formal2"> blah blah
<span class="test_formal2"><p class="test_formal">
blah blah <span class="test_formal2"><p class="test_formal"> blah blah
它匹配:
Search "^(?:(?!<p class="test_formal">).)*<span class="test_formal2">.*$" (3 hits in 1 file)
new 2 (3 hits)
Line 2: <span class="test_formal2">
Line 5: <span class="test_formal2"><p class="test_formal">
Line 6: blah blah <span class="test_formal2"><p class="test_formal"> blah blah