带方括号的分割字符串

时间:2018-07-09 23:18:44

标签: php python regex

我正在尝试使用preg_split拆分此文本

Yes, it was great. [I have no ideas how great it was.]

进入此数组:

['Yes', 'it', 'was', great', '[I have no ideas how great it was.]'

但是我不知道如何...

1 个答案:

答案 0 :(得分:1)

$keywords = preg_split("/[\s,.]+(?![^[]*])/", "Yes, it was great. [I have no ideas how great it was.]");
print_r($keywords);