Regex for managing escaped characters for items like string literals

后端 未结 6 890
别跟我提以往
别跟我提以往 2020-12-17 22:21

I would like to be able to match a string literal with the option of escaped quotations. For instance, I\'d like to be able to search \"this is a \'test with escaped\\\' val

6条回答
  •  感动是毒
    2020-12-17 22:53

    >>> print re.findall(r"('([^'\\]|\\'|\\\\)*')",r""" Example: 'Foo \' Bar'  End. """)[0][0]
    

    'Foo \' Bar'

提交回复
热议问题