0

I want to extract only the "Mlody" string from the below code. Matching should start from <dt>User</dt> and end at </dd> on the next line. I need some help on the RegEx code required. HTML code is below.

<dl>
<dt>User</dt>
<dd><a href="/users/837">Mlody</a></dd>
<dd></dd>
</dl>
Rynardt
  • 5,547
  • 7
  • 31
  • 43

1 Answers1

1

As a general rule, you shouldn't use a regex to match/parse the HTML text.

Instead, try a DOM parser (if available) and search for the tag you need, and then search the text content of those results with a regex if you need to match against the contents.

Only if you don't have any other option decide to use regex.

You can try following regex for matching multiline text:

<dt>User</dt>((?:.|[\r\n])*?)</dd>
anubhava
  • 761,203
  • 64
  • 569
  • 643