细绳:
testing = "\nHello\nMy name is blah blah blah\nNice to meet you\nPS: Wait a second, I thought I know you.\nRegards\n\nUnknown\n\nHang on a minute\nI'm not done talking\n\nRegards\nOh OK"
打印:
Hello
My name is blah blah blah
Nice to meet you
PS: Wait a second, I thought I know you.
Regards
Unknown
Hang on a minute
I'm not done talking
Regards
Oh OK
期望的结果:
My name is blah blah blah
Nice to meet you
PS: Wait a second, I thought I know you.
Regards
尝试的解决方案:
test = re.search('(Hello)([\s\S]*)(\n\n)', testing).group(2)
返回:
\nMy name is blah blah blah\nNice to meet you\nPS: Wait a second, I thought I know you.\nRegards\n\nUnknown\n\nHang on a minute\nI'm not done talking
但是,这错过了我认为与 [\s\S] 有关的第一个 '\n\n'。我们有什么办法可以在第一个 '\n\n' 处结束搜索?
慕的地10843
相关分类