Maison > Article > développement back-end > 正则有关问题来一发
正则问题来一发
问了下老徐,不过老徐最近很忙显然消息也没时间看,那就发出来给大家研究研究
能匹配以下两种情况,不是其中之一...
http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg
------解决方案--------------------
/^http://www.uploadfr.com/images/\d{4}/(\d{2}/){2}\S*.jpg$/
------解决方案--------------------
<br /><?php<br /><br />$str1 = 'http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg';<br />$str2 = 'http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg';<br /><br />$pattern = '/^http:\/\/www\.uploadfr\.com\/images\/(\d{4})\/(\d{2})\/(\d{2})\/([a-z0-9]+)\.(jpg<br><font color='#FF8000'>------解决方案--------------------</font><br>png<br><font color='#FF8000'>------解决方案--------------------</font><br>gif<br><font color='#FF8000'>------解决方案--------------------</font><br>jpeg)(\.thumb([a-z0-9]{6})\.\\5)?$/';<br /><br />preg_match($pattern, $str1, $match1);<br />preg_match($pattern, $str2, $match2);<br /><br />print_r($match1);<br />print_r($match2);<br />
<br />$content=<<<TXT<br />字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg字字字字字字字字字字字字字字字字http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg字字字字字字字字字字字字字字字字<br />TXT;<br /><br />preg_match_all('/http:\/\/www.uploadfr.com\/images\/\d{4}\/\d{2}\/\d{2}\/\d{6}.*?jpg(\.thumb[a-z0-9]{6}\.jpg)?/si', $content, $matches);<br /><br />print_r($matches[0]);<br />