python regex匹配所有字面值字符之间的字符串



我是新的python regex我正试图写一个正则表达式来匹配字符之间的字符串,这是文字

my_string = "```,null,")]}'n[["102fb5","```"

我想要的是102fb5

我写的正则表达式:

"```n[[\"((?:.|n)*?)\"```"

首先,我建议您使用Python原始字符串,这将使您的RegEx更具可读性,因为您不需要转义每个反斜杠:

QUERY = r'```n[["((?:.|n)*?)"```'

然而,我不确定为什么你要费心匹配整个列表结构,当你可以只搜索"literals"通过标识它们的引号:

# "(.*?)"
# Match escaped quotation mark: "
# Match the literal text: .*?
# Match the other escaped quotation mark: "
>>> re.findall(r'"(.*?)"', '''```,null,")]}'n[["102fb5",```"'n[["102fb5","```''')
['102fb5', '102fb5']

最新更新