Muhtemelen böyle bir şey arıyor:
/<li(?:(?!class=['"]second['"])[^>])*>(?:(?!<\/li>).)*<\/li>/
Fikir yakalayan ifadeler içinde gruplandırılmış negatif İleriye iddialar kullanılarak dayanmaktadır. Burada karmaşık faktörler insanların HTML ayrıştırmak regexpi kullanarak karşı öneririz ana nedenlerinden biridir.
RegExp açıklanması:
/ - 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