Is there any regular expression 开发者_StackOverflow中文版to match this:
- a continuous string of characters or/and digits XOR
- a string of any characters between a pairquotation marks (" XOR ')including nested quotations
?
Examples:
- dgsdggsgggdggsggsd
- 'dsfsasf .asgafaasfafw rq'
- "sadas fa fasfa "
Perhaps relevant: do you know about the shlex module?
Maybe you can try this:
>>> message = "blabla df qdsf dqsf \"fqdfdqsfsdf fdqs fqdsf\""
>>> pattern = "(\w+|'.*[^']'|\".*[^\"]\")"
>>> re.findall(pattern, message)
['blabla', 'df', 'qdsf', 'dqsf', '"fqdfdqsfsdf fdqs fqdsf"']
精彩评论