Use PHP for splitting on spaces and brackets

后端 未结 5 870
醉梦人生
醉梦人生 2021-01-21 09:03

I have this string in $s:

ben say (#yellow) hey

At the moment I\'m using:

$parts = array_filter(preg_sp         


        
5条回答
  •  佛祖请我去吃肉
    2021-01-21 09:38

    You could split it by Lookahead and Lookbehind Zero-Width Assertions:

    $parts = array_filter(preg_split('/\s+|(?=[()])|(?<=[()])/', $s));
    

提交回复
热议问题