如何将“的符号分组”;“不在范围内”;PHP中的表达式?
如何在PHP中对“不在范围内”表达式的符号进行分组如何将“的符号分组”;“不在范围内”;PHP中的表达式?,php,regex,Php,Regex,如何在PHP中对“不在范围内”表达式的符号进行分组 列出第1项 列出第2项 列出第3项 列出第4项 我想对所有li元素进行cath,除了一个带有class=“second”的元素 这不起作用: /(PHP不支持“本机”正则表达式,但是可以使用它来执行正则表达式 编辑:另外,您的表达式中没有转义“/”,这意味着提前终止调用。您可能正在寻找类似以下内容: /<li(?:(?!class=['"]second['"])[^>])*>(?:(?!<\/li>).)*<
编辑:另外,您的表达式中没有转义“/”,这意味着提前终止调用。您可能正在寻找类似以下内容:
/<li(?:(?!class=['"]second['"])[^>])*>(?:(?!<\/li>).)*<\/li>/
/不使用regexp解析X?HTML:
/ - Start Regexp
<li - Match '<li'
(?: - Start Non-Capture Group
(?! - Start Negative Lookahead:
- Ensure this group does not match (doesn't increment pointer either)
class= - Match 'class='
["'] - Match ' or "
second - Match 'second'
["'] - Match ' or "
) - End Negative Lookahead,
- If it matched that whole segment, fail, otherwise:
[^>] - Match anything but '>'
)* - End Non-Capture Group - match 0 or more times
> - Match '>'
(?: - Start Non-Capture Group
(?! - Start negative lookahead
<\/li> - Match '</li>'
) - Ensure lookahead doesn't match, otherwise:
. - Capture any character
)* - End Non-Capture Group, match 0 or more times
<\/li> - Match '</li>'
/ - End RegExp