开发者

Python regular expressions

开发者 https://www.devze.com 2023-01-22 11:50 出处:网络
Is there any regular expression 开发者_StackOverflow中文版to match this: a continuous string of characters or/and digits XOR

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

精彩评论

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