我在我的PHP代碼中的正則表達式應該每個數字和所有的「運營商」 +匹配 - */^ R()我的正則表達式看起來像這樣PHP正則表達式意外的比賽
/(?:(\d+(?:\.\d+)|(\+)|(-)|(\*)|(\/)|(\^)|(r)|(\()|(\))))/
和測試時以字符串preg_match_all($expression,"2+2",$results)
它給我回
Array
(
[0] => Array
(
[0] => '+'
)
[1] => Array
(
[0] => ''
)
[2] => Array
(
[0] => '+'
)
[3] => Array
(
[0] => ''
)
[4] => Array
(
[0] => ''
)
[5] => Array
(
[0] => ''
)
[6] => Array
(
[0] => ''
)
[7] => Array
(
[0] => ''
)
[8] => Array
(
[0] => ''
)
[9] => Array
(
[0] => ''
)
)
當(如果它的工作原理右)我應該得到這個
Array
(
[0] => Array
(
[0] => '2'
[1] => '+'
[2] => '2'
)
[1] => Array
(
[0] => '2'
[1] => ''
[2] => '2'
)
[2] => Array
(
[0] => ''
[1] => '+'
[2] = > ''
)
[3] => Array
(
[0] => ''
[1] => ''
[2] => ''
)
[4] => Array
(
[0] => ''
[1] => ''
[2] => ''
)
...
)
注意,它返回類似行爲對於所有的運營商,它似乎忽略的數字完全
注意,我確實需要單獨的捕捉組,所以我有不同的匹配指標。對於每個結果
這是什麼目標? 「 –
」應該匹配每個數字和所有「運算符」+ - */^ r()「我試圖基於這個正則表達式來標記化 – Nanos
然後你不需要使用分離的捕獲組 –