我有以下字符串:正则表达式不捕获所有信息
a = '''"The cat is running to the door, he does not look hungry anymore".
Said my mom, whispering.'''
注意换行符。在Python中的字符串将是: 'The cat is running to the door, he does not look hungry anymore".\n \n Said my mom, whispering.'
我有这样的正则表达式: pattern = u'^("|«)(.*?)("|»)(.*?)\u000A{1,}(.*?)'
,我作为在Python如下:
>>> import re
>>> a = '''"The cat is running to the door, he does not look hungry anymore".
Said my mom, whispering.'''
>>> pattern = u'^("|«)(.*?)("|»)(.*?)\u000A{1,}(.*?)'
>>> re.search(pattern, a).groups()
>>> ('"', 'The cat is running to the door, he does not look hungry anymore', '"', '.', '')
为什么最后一部分(Said my mom, whispering.
)是不是被被正则表达式抓住了? 我期待这样的事情:
>>> ('"', 'The cat is running to the door, he does not look hungry anymore', '"', '.', 'Said my mom, whispering.')
能否请您澄清我,我做错了什么?
这不是全球性的? – Downgoat
变量'a'? @ vihan1086 – gglasses
[regex101](https://regex101.com/#python)正则表达式测试程序可以真正有助于调试正则表达式代码。 – tegancp