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

demo


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -