PHP: How to replace only one line using a regex? -


this question has answer here:

i have string:

<li id="1">3431233</li> <li id="2">fsdfdsfsdfdsfdsf</li> <li id="3">abc</li> <li id="4"> fdsf2342343</li> <li id="5">123</li> 

i want replace lines containing abc or 123 nothing (3rd , 5th in case). problem regex wont work:

^<li>abc<\/li> 

it replaces lis. how can limit replaceing 1 line? li differ line line , thats dynamic, not know how (what classes , ids might have.)

thanks!

try here

^<li id="[0-9]">(abc|123|)<\/li> 

use [0-9]+ if id grows

^<li id="[0-9]+">(abc|123|)<\/li> 

Comments