replace - RegEx match first occurrence before keyword -
i have following string:
<ul><li><span>some words here.</span></li><li><span>other words here.</span></li><li><span>code: 55555.</span></li></ul>
my goal remove part string, set of li tags contain "code" keyword:
<li><span>code: 55555.</span></li>
i trying write regex me match , replace substring. text in between <li></li>
might vary have keyword "code". have far:
<li>(.*)code:(.*?)<\/li>
the problem is, matches first <li>
tag , want match starting <li>
tag right before our keyword "code".
thank help!
<li>(?:.(?!</li>))+code:(?:.*?)</li>
- match
<li>
literally - followed number of characters literal
</li>
doesn't match (this ensures match start @ relevant<li>
) - followed literal
code:
- followed number of characters (non-greedy) until literal
</li>
matched
Comments
Post a Comment