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.

Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
mrdaliri
  • 6,816
  • 22
  • 70
  • 102

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
  • 48,485
  • 14
  • 85
  • 106