Who can change the regular expression? This is the content to match: & nbsp; & lt; dl & gt; & lt; dt & gt; 2013 & lt;/dt & gt; & lt; dd & gt; row1 & lt;/dd & gt; & lt; dd & gt; row2 & lt;/dd & gt; & lt; dd & gt; row3 & lt; /dd & gt; & lt; who can change the regular expression?
This is the content to match:
-
2013
-
row1
-
row2
-
row3
-
2014
-
row1
-
row2
To match dl, and dt under dl, and all dd,
I wrote it like this:
\s+
-
(.*?)
(\s+
-
(.*?)
\s+)*?
However, this matching result is not correct. dd always matches only the last one. How should I modify this expression? Regular expression sharing:
2013
Row1
Row2
Row3
-
201... 'data-pics = ''>
------ Solution --------------------
Separate and match. The dl matches once and the dt and dd in it matches again.
------ Solution --------------------
Flexible (the number of items to be matched is not fixed, and the formal language is basically impossible)
preg_match_all('#<(d[dt])>\s*([^<]+)
#is', $s, $r);
print_r($r);Array
(
[0] => Array
(
[0] =>
-
2013
[1] =>
-
Row1
[2] =>
-
Row2
[3] =>
-
Row3
[4] =>
-
2014
[5] =>
-
Row1
[6] =>
-
Row2
)
[1] => Array
(
[0] => dt
[1] => dd
[2] => dd
[3] => dd