regex for triple quote

后端 未结 5 658
我在风中等你
我在风中等你 2020-12-19 06:32

What regex will find the triple quote comments (possibly multi-line) in a Python source code?

5条回答
  •  时光说笑
    2020-12-19 07:13

    I don't know how well this will fair when scanning Python code, but this seems to match Python strings in isolation.

    ^(\"([^\"\n\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*\"|'([^'\n\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*'|\"\"\"((?!\"\"\")[^\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*\"\"\")$
    

    The escaping is not standard Python; this is something that I cut-n-pasted from a project. See it in action at regex101.com.

提交回复
热议问题