This is a simple regular expression for beginners. thank you for your help.

Source: Internet
Author: User
This is a simple regular expression for beginners. thank you! This post was last edited by bupabupa166 from 2014-10-3122: 08: 43 & lt; a & nbsp; titlewomen & nbsp; bags & nbsp; data-textwomen & nbsp; bags & nbsp; hrefht is a simple regular expression for beginners. thank you.

This post was last edited by bupabupa166 at 22:08:43

Women bags Backpack WalletBag Men KeysoolBag Dress Handbag ShoulderBag Purse ShoesBag Man LeatherBag


How can I use regular expressions to match the attribute values of all "data-text" (values in quotation marks ).
Thank you.
------ Solution ----------------------
 $str='women bags backpack wallet bag men keysool bag dress handbag shoulder bag purse shoes bag man leather bag';

preg_match_all('/data-text="(.+)"/U',$str,$matches,PREG_PATTERN_ORDER );

var_dump($matches[1]);








array(12) {
[0]=>
string(10) "women bags"
[1]=>
string(8) "backpack"
[2]=>
string(6) "wallet"
[3]=>
string(7) "bag men"
[4]=>
string(11) "keysool bag"
[5]=>
string(5) "dress"
[6]=>
string(7) "handbag"
[7]=>
string(12) "shoulder bag"
[8]=>
string(5) "purse"
[9]=>
string(5) "shoes"
[10]=>
string(7) "bag man"
[11]=>
string(11) "leather bag"
}

------ Solution ----------------------
Write a relatively intuitive one. first, extract the information in the data-text = "..." quotation marks from the single link.

// Match the first half of the hyperlink, for example
Function filterLink ($ data)
{
$ Pat = '#] +?> # Ui ';
If (preg_match_all ($ pat, $ data, $ match ))
{
Foreach ($ match [0] as $ link)
{
// Echo $ link ."

";
FilterData ($ link );
}
}
Else
{
Echo 'matching failed ';
}
}

// Then extract the required information from a single object
Function filterData ($ data)
{
$ Pat = '# data-text = "([^"] + ?) "# I ';
If (preg_match_all ($ pat, $ data, $ match ))
{
Foreach ($ match [1] as $ content)
{
Echo $ content ."
";
}
}
Else
{
Echo 'matching failed ';
}
}
FilterLink ($ str );


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.