Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要匹配以下组:
:data: :abc'e12\:3\:text:
在一个字符串中,意思是
:(?P<data>.*?):
但也允许转义冒号\:
\:
我最好的尝试是这样的:
:(?P<data>((?<=\\):|.)*?):
p = re.compile(r':((\\:|[^:])+):') print p.match(":abc'e12\:3\:text:").group(0)
您始终可以确保使用“^”和“$”获取开始和结束字符:
^:(.+):$
您也可以将“.+”替换为您想要的正则表达式类型。