Home  >  Article  >  Backend Development  >  真心求教正则表达式,该如何处理

真心求教正则表达式,该如何处理

WBOY
WBOYOriginal
2016-06-13 10:11:51917browse

真心求教正则表达式
谁帮我把以下代码中,用正则表达式提取以下3个数据呢?
第一:alt="Mexico" 中的 Mexico
第二:7732078 中的 7732078
第三:A 14 中的 A 14

 

谢谢了。

------解决方案--------------------
PHP code
<?php $str=<<<HTML<div class="items">  <a class="imo-block" href="/site/details?imo=7732078">  <img title="Mexico" src="/images/flags/mx.png" alt="Mexico"> <span class="imo">7732078</span>  <br>  <span class="vessel-name">A 14</span>  </a>  <a class="imo-block" href="/site/details?imo=7528398">  <img title="Mexico" src="/images/flags/mx.png" alt="China"> <span class="imo">7528398</span>  <br>  <span class="vessel-name">A 15</span>  </a>HTML;preg_match_all('/alt="(.*?)"|class="imo">(.*?)(.*?)',$str,$matchs);print_r($matchs);<br><font color="#e78608">------解决方案--------------------</font><br>$re1 = '/alt="[a-zA-Z]*[^"]/i';<br>$re2 = '/<span class="imo">\d*[^\$re3 = '/<span class="vessel-name">[a-zA-Z0-9 ]*[^\$match ='';<br>preg_match_all($re1, $str, $match);<br>echo '<pre class="brush:php;toolbar:false">';<br>print_r($match);<br>第一个$re1还有点问题,你在想一想吧<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn