細(xì)繩: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"打?。篐elloMy name is blah blah blahNice to meet youPS: Wait a second, I thought I know you.RegardsUnknownHang on a minuteI'm not done talkingRegardsOh OK期望的結(jié)果:My name is blah blah blahNice to meet youPS: 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但是,這錯(cuò)過(guò)了我認(rèn)為與 [\s\S] 有關(guān)的第一個(gè) '\n\n'。我們有什么辦法可以在第一個(gè) '\n\n' 處結(jié)束搜索?
正則表達(dá)式:匹配字符+換行之前(換行換行)
人到中年有點(diǎn)甜
2023-03-16 15:55:08