如果我使用preg_split()函數例如:$string = 'products{id,name},articles{title,text}';$arr = preg_split('/\}\,(\w)/', $string);print_r($arr);我收到以下結果:Array ( [0] => products{id,name [1] => rticles{title,text} )如何接收全文文章,即提取正則表達式模式的值?附:如果可能的話
1 回答

POPMUISE
TA貢獻1765條經驗 獲得超5個贊
您可以在匹配大括號時進行拆分,清除匹配緩沖區。然后匹配逗號并使用正向前瞻斷言右側的單詞字符而不是匹配它。
{[^{}]*}\K,(?=\w)
模式匹配:
{
匹配{
[^{}]*
匹配 0+ 次除{
and之外的任何字符}
}
匹配}
\K,
到現在都忘記匹配什么了,匹配一個逗號(?=\w)
正向前瞻,斷言右邊直接的是單詞字符
$string = 'products{id,name},articles{title,text}'; $arr = preg_split('/{[^{}]*}\K,(?=\w)/', $string); print_r($arr);
輸出
Array( [0] => products{id,name} [1] => articles{title,text} )
- 1 回答
- 0 關注
- 105 瀏覽
添加回答
舉報
0/150
提交
取消