2014-10-01 65 views
0

我有以下代碼:的preg_match星號

preg_match('/^\bcount\(\b(?P<name>\w+)\) AS (?P<newName>\w+)$/', $attr, $matches); 

此時,只接受字符串,如果他們的形式爲 「計數(someword)AS someword」 的。但我希望它也接受字符串,如果它說:count(*) AS bla

我試過(\w+|\*),但這並沒有工作。

有什麼建議嗎?

回答

2

你關閉,刪除\b

preg_match('/^\bcount\((?P<name>\w+|\*)\) AS (?P<newName>\w+)$/', $attr, $matches);