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>
4

1 回答 1

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>
于 2013-03-30T14:47:24.370 回答