我有一个字符串(A) fdkf djkf gsdfjkg hsfl (B) jfg dkfjg hdksfjg dkfj (c) ndfkj gndfg ndfn (d) kdjfskdj fs;s dknls期望的输出应该是这样的4 group matched(A) fdkf djkf gsdfjkg hsfl(B) jfg dkfjg hdksfjg dkfj(c) ndfkj gndfg ndfn(d) kdjfskdj fs;s dknls请帮忙我正在尝试/((.+?) (?=\())/正则表达式,但它没有创建 4 个组我在这里尝试创建这种模式 https://regex101.com/r/KxAcaV/1$re = '/((.+?) (?=\())/';$str = '(A) fdkf djkf gsdfjkg hsfl (B) jfg dkfjg hdksfjg dkfj (c) ndfkj gndfg ndfn (d) kdjfskdj fs;s dknls';preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);// Print the entire match resultvar_dump($matches);
3 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
$str = '(A) fdkf djkf gsdfjkg hsfl (B) jfg dkfjg hdksfjg dkfj (c) ndfkj gndfg ndfn (d) kdjfskdj fs;s dknls';
preg_match_all('/\(.+?\).+?(?= \(|$)/', $str, $m);
print_r($m[0]);
输出:
Array
(
[0] => (A) fdkf djkf gsdfjkg hsfl
[1] => (B) jfg dkfjg hdksfjg dkfj
[2] => (c) ndfkj gndfg ndfn
[3] => (d) kdjfskdj fs;s dknls
)
- 3 回答
- 0 关注
- 127 浏览
添加回答
举报
0/150
提交
取消