<?php
$str = '<div id="Div3" class="modResumeInfo">
<div class="title" onclick="clickLabel(rsmEduExCt)">
<div class="dcrL dcrArrowGreen"></div>
<h3>外语能力</h3>
</div>
<div id="Div4" class="content">
<div class="workExCom">英语:读写能力精通 | 听说能力熟练</div>
<div class="workExCom">韩语:读写能力一般 | 听说能力良好</div>
<div class="workExCom">德语:读写能力一般 | 听说能力一般</div>
</div>
</div><!--modResumeInfo结束-->
我想取出英语 韩语 德语这三个词,用正则表达是怎么写?
用这种格式:
前字符串(?<content>[\s\S]*?)后字符串
------解决方案--------------------
- PHP code
$str = '<div id="Div3" class="modResumeInfo"> <div class="title" onclick="clickLabel(rsmEduExCt)"> <div class="dcrL dcrArrowGreen"></div> <h3>外语能力</h3> </div> <div id="Div4" class="content"> <div class="workExCom">英语:读写能力精通 | 听说能力熟练</div> <div class="workExCom">韩语:读写能力一般 | 听说能力良好</div> <div class="workExCom">德语:读写能力一般 | 听说能力一般</div> </div> </div><!--modResumeInfo结束-->'; preg_match_all('@<div class="workExCom">(.+):(.+)</div>@u',$str,$match); var_dump($match[1]);
------解决方案--------------------
- PHP code
$str=<<< TEXT <div id="Div3" class="modResumeInfo"> <div class="title" onclick="clickLabel(rsmEduExCt)"> <div class="dcrL dcrArrowGreen"></div> <h3>外语能力</h3> </div> <div id="Div4" class="content"> <div class="workExCom">英语:读写能力精通 | 听说能力熟练</div> <div class="workExCom">韩语:读写能力一般 | 听说能力良好</div> <div class="workExCom">德语:读写能力一般 | 听说能力一般</div> </div> </div><!--modResumeInfo结束--> TEXT; preg_match_all("/<div\s+class=\"workExCom\">(.*):/",$str,$arr); print_r($arr);