python特定段落的文本匹配
問題描述
a=’’’[Scene: Central Perk, Chandler, Joey, Phoebe, and Monica are there.]Monica: There’s nothing to tell! He’s just some guy I work with!Joey: C’mon, you’re going out with the guy! There’s gotta be something wrong with him!Chandler: All right Joey, be nice.? So does he have a hump? A hump and a hairpiece?Phoebe: Wait, does he eat chalk?[Scene: Chandler, Joey,abcsde.]Phoebe: Just, ’cause, I don’t want her to go through what I went through with Carl- oh!Monica: Okay, everybody relax. This is not even a date. It’s just two people going out to dinner and- not having sex.Chandler: Sounds like a date to me.[Scene: Joey.]’’’
我有一段文本a,如上,我想取得每個場景的對話文本,保存成lsit,每個場景的區(qū)分是[Scene: 加一句英文.],如上面加粗的部分然后用正則表達式寫,paragraphs = re.findall(’[Scene: w+.](.*?)[Scene: w+.]’,a,re.S)
我發(fā)現(xiàn)沒有匹配出內(nèi)容來,paragraphs是個空的,請問錯誤的原因在哪,該如何去匹配每一場景的對話內(nèi)容?謝謝。
問題解答
回答1:錯誤有幾點沒有使用原生字符串沒有轉(zhuǎn)義[
以下是我修改后的代碼。
paragraphs = re.findall(r'[Scene: [ws,]+.]s([^[]+)s(?=[Scene: [ws,]+.])', a, re.S)
python正則表達式指南http://www.cnblogs.com/huxi/a...
相關(guān)文章:
1. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. 關(guān)于docker下的nginx壓力測試3. nignx - docker內(nèi)nginx 80端口被占用4. android - 百度地圖加載完成監(jiān)聽5. dockerfile - [docker build image失敗- npm install]6. java - 阿里的開發(fā)手冊中為什么禁用map來作為查詢的接受類?7. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗!8. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么?9. macos - mac下docker如何設(shè)置代理10. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下
