正则表达式不工作Python

时间:2013-10-11 23:47:00

标签: python regex

我正在尝试使用正则表达式来匹配“[stuff]”。可以有转义字符,但只要有偶数字,它们什么也不做。我的正则表达是:

(?<!\\\\)(\\\\\\\\)*\".*?(?<!\\\\)(\\\\\\\\)*\"

当第二个引号的偶数为\时,它将匹配,即("a daf asd \\"

但不是第一个引用时(即\\" adf "

任何人都有任何想法,为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

如果我清楚你想要做什么,请尝试使用以下内容。

(?<!\\)(?:\\\\)*".*?(?<!\\)(?:\\\\)*"

正则表达式解释:

(?<!\\)    Matches if the preceding char is not a backslash
(?:\\\\)*  Matches 0 or more occurrences of two backslashes
"          Matches a double quote
.*?        Matches any character except \n (0 or more times)

Repeat lines 1-3

请参阅live demo

相关问题