取子串的正则表达式
有如下字符串:
"
用正则表达式如何取出"name1"和"name2"呢?谢谢
------解决方案--------------------
- PHP code
<?php $str = "name1 name2 "; $patten = "/([^/isU"; preg_match_all($patten,$str,$matches); print_r($matches[1]);
------解决方案--------------------PHP code
$str = "name1 name2 "; preg_match_all('/>([^ name1 [1] => name2 ) */
------解决方案--------------------PHP code
preg_match_all("/>[^------解决方案--------------------
$str = "name1 name2 ";
preg_match_all('/>([^print_r($matches[1]);
/**
输出结果:
Array ( [0] => name1 [1] => name2 )
*/
------解决方案--------------------PHP code
<?php $str="name1 name2 "; $preg="#(.*) (.*) #"; preg_match($preg,$str,$arr); echo $arr[1]; echo $arr[2]; ?>
------解决方案--------------------
<?php
$str="name1 name2 ";
preg_match_all("/([^]*)/",$str,$matches);
echo $matches[1][0];
echo $matches[1][1];
?>
------解决方案--------------------
"/>(.*?)------解决方案--------------------
------解决方案--------------------
<?php
$str="name1 name2 ";
preg_match_all("/([^]*)/",$str,$matches);
echo $matches[1][0];
echo $matches[1][1];
?>