Help write a regular expression

Source: Internet
Author: User
Help write a regular expression
 
 
Alice cos alice dress alice in Wonderland alice crazy back alice flower pot alice hand office alice girl alice school alice Phil alice hand bag alice retro

I want to retrieve
To
Between the title value and the href value in this section, because this format is also available elsewhere on this page, so now you can directly use
$contents_key = '~~';preg_match_all($contents_key,$html,$contentskey);
This will include the same format outside the dd tag. how can I write this regular expression?


Reply to discussion (solution)

In two steps, match the content in the dd label before applying your regular expression.

First

To
And then parse the title and link.

In two steps, match the content in the dd label before applying your regular expression.
However, the dd tag cannot be captured directly.

There are many spaces in the dd tag. I use (.*?) Not matched.

What is the final result you want?

What is the final result you want?
I want title = "here is what I want" href = "here is what I want", and it is best to have a regular expression. I feel that the two regular expressions must match twice, is efficiency a little too low?

$ S = <
 
  
Alice cos alice dress alice in Wonderland alice crazy back alice flower pot alice hand office alice girl alice school alice Phil alice hand bag alice retroDafdsafp; preg_match ('/
  
 
(. + ?) <\/Dd>/S', $ s, $ m); echo $ m [1];


Alice cos
Alice dress
Alice in Wonderland
Alice crazy regression
Alice pot
Alice hands-on
Alice
Maids
Alice's school
Alice Phil
Alice handbag
Alice Vintage

Try to match the dd content

$pattern = '/
 
 
.*<\/dd>/is'

Modifier I: case-insensitive
Modifier s: a "dot" in the pattern will match all characters, including line breaks. without him, line breaks will be excluded. This modifier is equivalent to the/s modifier in Perl.

$contents_key = '~
 
 
([\s\S]*?)
~';

I thought about it myself. this is done.
Related Article

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.