日期:2014-05-17  浏览次数:20484 次

求正则表达式
字符串:
PHP code

 <a href="teamMemberDisplay.php?tid=650" title='Team' >SW Design and ISS Scrum Team 2</a><br>

<a href="programDisplay.php?pid=17" title='Program/Domain/BU'>LR RF & HW Modules</a>-&gt;<a href="tdlDisplay.php?pid=119" title='Technical Domain'>LR WCDMA CPRI Baseline</a>-&gt;<a href="projectDisplay.php?pid=123" title='Project'>LR CPRI Misc.</a>-&gt;<a href="teamMemberDisplay.php?tid=576" title='Team' >SW Dev and Test</a>



求将 LR RF & HW Modules,LR WCDMA CPRI Baseline, LR CPRI Misc. ,SW Dev and Test 这四个取出来的正则,以及只取出LR RF & HW Modules的正则表达式。
我在php里用的函数是preg_match.
谢谢了!!

------解决方案--------------------
PHP code

$str=<<<html
<a href="teamMemberDisplay.php?tid=650" title='Team' >SW Design and ISS Scrum Team 2</a><br> 
<a href="programDisplay.php?pid=17" title='Program/Domain/BU'>LR RF & HW Modules</a>-&gt;<a href="tdlDisplay.php?pid=119" title='Technical Domain'>LR WCDMA CPRI Baseline</a>-&gt;<a href="projectDisplay.php?pid=123" title='Project'>LR CPRI Misc.</a>-&gt;<a href="teamMemberDisplay.php?tid=576" title='Team' >SW Dev and Test</a> 
html;
//echo $str;quit();
preg_match_all('/(?:\s+|-&gt;)<a[^>]*>(.*)<\/a>/isU',$str,$arr);
print_r($arr[1]);

------解决方案--------------------
$text=array();
$html="<a href=\"teamMemberDisplay.php?tid=650\" title='Team' >SW Design and ISS Scrum Team 2</a><br>
<a href=\"programDisplay.php?pid=17\" title='Program/Domain/BU'>LR RF & HW Modules</a>
<a href=\"tdlDisplay.php?pid=119\" title='Technical Domain'>LR WCDMA CPRI Baseline</a>
<a href=\"projectDisplay.php?pid=123\" title='Project'>LR CPRI Misc.</a>
<a href=\"teamMemberDisplay.php?tid=576\" title='Team' >SW Dev and Test</a>";
preg_match_all('|Program\/Domain\/BU\'>(.+)<\/a>|',$html, $matches);
$text[0]=$matches[1][0];
preg_match_all('|Technical Domain\'>(.+)<\/a>|',$html, $matches);
$text[1]=$matches[1][0];
preg_match_all('|Project\'>(.+)<\/a>|',$html, $matches);
$text[2]=$matches[1][0];
preg_match_all('|title=\'Team\' >(.+)<\/a>|',$html, $matches);
$text[3]=$matches[1][1];
print_r($text);
------解决方案--------------------
(?:Expression) 非捕获组 进行子表达式Expression的匹配,并将匹配内容保存到最终的整个表达式的区配结果中,但Expression匹配的内容不单独保存到一个组内

| 或的意思