Which of the following experts can help you change the regular expression?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.