开发者

Python regular expressions

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"']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜