Splitting strings in python
问题 I have a string which is like this: this is [bracket test] "and quotes test " I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is: ['this','is','bracket test','and quotes test '] 回答1: Here's a simplistic solution that works with your test input: import re re.findall('\[[^\]]*\]|\"[^\"]*\"|\S+',s) This will return any code that matches either a open bracket followed by zero or more non-close