RegEx匹配不包含特定HTML标记的字符串

Nia*_*yle 3 regex wildcard

我想使用正则表达式来查找两个标签之间的内容,如下所示:

<br />@ This is the content.</li>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我一直在使用:

<br />@(.*?)</li>
Run Code Online (Sandbox Code Playgroud)

内容有时包含<li>标签,这不是我想要的.所以现在我想修改我的搜索,例如match <br />@(.*?)</li>不包含<li> tag.

然后我尝试:<br />@([^<li>].*?)</li>,但这仍包括<li>在搜索中.

你能给我一点帮助吗?谢谢.(注意,我使用TextWrangler)

Ro *_* Mi 5

描述

这个表达式将:

  • 找到以下一个开头<br />和结尾的子串</li>
  • 验证子字符串不包含 <li>
  • 捕获上面定义的开始结束标记之间的文本

<br\s*\/>(@(?:(?!<li>).)*?)<\/li>

在此输入图像描述

示范文本

实例:http://www.rubular.com/r/CIledJX54O

注意第一行的状况不好

<br />@ Don't <li>find me.</li>
<br />@ This is the content.</li>
<br />@ more desired content.</li>
Run Code Online (Sandbox Code Playgroud)

捕获组

[0] => Array
    (
        [0] => <br />@ This is the content.</li>
        [1] => <br />@ more desired content.</li>
    )

[1] => Array
    (
        [0] => @ This is the content.
        [1] => @ more desired content.
    )
Run Code Online (Sandbox Code Playgroud)