[英]python regex to match string between all literal characters
我是 python 正则表达式的新手 我正在尝试编写一个正则表达式来匹配文字字符之间的字符串
my_string = "```,null,")]}'\n[[\"102fb5\",\"```"
我想要的是102fb5
。
我写的正则表达式:
"```n\[\[\\\"((?:.|\n)*?)\\"```"
首先,我建议您使用 Python 原始字符串,这将使您的 RegEx 更具可读性,因为您不需要转义每个反斜杠:
QUERY = r'```n\[\[\"((?:.|\n)*?)\"```'
但是,我不确定您为什么要费心匹配整个类似列表的结构,而您只需通过识别引号来搜索“文字”本身:
# \"(.*?)\"
# Match escaped quotation mark: \"
# Match the literal text: .*?
# Match the other escaped quotation mark: \"
>>> re.findall(r'\"(.*?)\"', '''```,null,")]}'\n[[\"102fb5\",```"'\n[[\"102fb5\",\"```''')
['102fb5', '102fb5']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.