REGEX-字符串和转义引号

发布于 2021-01-29 14:10:39

如何获得以下两个文本中引号之间的含义?

text_1 = r""" "Some text on \"two\" lines with a backslash escaped\\" \
     + "Another text on \"three\" lines" """

text_2 = r""" "Some text on \"two\" lines with a backslash escaped\\" + "Another text on \"three\" lines" """

我的问题是,如果引号被转义,则应将其忽略,但是有可能使反斜杠转义。

我想获得以下团体。

[
    r'Some text on \"two\" lines with a backslash escaped\\',
    r'Another text on \"three\" lines'
]
关注者
0
被浏览
124
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。
    "(?:\\.|[^"\\])*"
    

    匹配带引号的字符串,包括其中出现的所有转义字符。

    说明:

    "       # Match a quote.
    (?:     # Either match...
     \\.    # an escaped character
    |       # or
     [^"\\] # any character except quote or backslash.
    )*      # Repeat any number of times.
    "       # Match another quote.
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看