【发布时间】:2013-07-26 07:27:19
【问题描述】:
要解析的字符串:
$str = "
public $xxxx123;
private $_priv ;
$xxx = 'test';
private $arr_123 = array();
"; // | |
// ^^^^^^^---- get the variable name
我得到了什么:
$str = preg_match_all('/\$\S+(;|[[:space:]])/', $str, $matches);
foreach ($matches[0] as $match) {
$match = str_replace('$', '', $match);
$match = str_replace(';', '', $match);
}
它有效,但我想知道我是否可以改善怀孕,例如摆脱这两个str_replace 并可能在(;|[[:space:]]) 中包含\t
【问题讨论】:
标签: php regex preg-match-all pcre