简体   繁体   中英

regular expression with new line

I want the string FC Barcelona v BM Huesc , FC Ferrari v BM ameriF and C semari v AM buhari from below code.

$mat = '<font color="white">FC Barcelona v BM Huesca

<font color="white">FC Ferrari v BM ameri

<font color="white">FC semari v AM buhari
';

I tried below code , but it does not seems to work.Any help will be appreciated.Thanks

preg_match_all('/<font color="white">(.*?)/',$mat,$mats);
var_dump($mats);

Edit: My real time example is below

<?php
$game = file_get_contents("http://www.firstrow1.eu/bet365/index.html");
preg_match_all('/<\/td><td><font color="white">(.*)/m',$game,$mats);
var_dump($mats);
?>

.*? will match nothing because it is relucant and matches as little as possible. Since there is no other part of the expression after it, it is done when it has matched nothing. Use .* because with all its greediness it will only match up to the end of the line. Note that this is true regardless of whether you use the m modifier or not.

preg_match_all("#<font color=\"white\">(.*?)\n#si", $mat, $mats);

有用!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM