import re #pat = r"""\s+|'.+'""" #t = re.compile(pat) #dl= " aaa 'bbb' xxxx c " #print dl #print t.split(dl) pat = r"""'.+'|".+"|\S+""" t = re.compile(pat) dl= """ 'l m' aaa 'bbb' xxxx " gg g " c """ print dl print t.findall(dl)