MadCom MadCom - 6 days ago 5
PHP Question

Find tags with text inside

I have this text string

<div><div>Content</div><div><span>Searching</span></div></div>


And I'm searching for
div
tag which have text
Searching
inside them. So I need regex which will match

<div><span>Searching</span></div>


Closest what I got is with

<div>(.*?)Searching(.*?)<\/div>


but it matches from the first
div
and result is

<div><div>Content</div><div><span>Searching</span></div>

Answer

Using a negative look-ahead should do it for you:

<div>((?:(?!<div>).)*)Searching(.*?)<\/div>

See it here at regex101.