0

How to find an element contains a string? by regex. for example, i want to find elements contains string:

<div class="a"><span id="d">string</span></div>
<span style="color: red;">string</span>
<p class="c">string</p>

it should return: <span id="d">string</span>, <span style="color: red;">string</span>, <p class="c">string</p>.

thanks.

mrdaliri
  • 7,148
  • 22
  • 73
  • 107

1 Answers1

0

The almost closest:

<([^ >]+)[^>]*>string</\1>

But it can fail on several badly formatted examples. And you should read one of the best answers on this topic.

HTH

Community
  • 1
  • 1
Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110