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,每個場景的區分是[Scene: 加一句英文.],如上面加粗的部分然后用正則表達式寫,paragraphs = re.findall(’[Scene: w+.](.*?)[Scene: w+.]’,a,re.S)
我發現沒有匹配出內容來,paragraphs是個空的,請問錯誤的原因在哪,該如何去匹配每一場景的對話內容?謝謝。
問題解答
回答1:錯誤有幾點沒有使用原生字符串沒有轉義[
以下是我修改后的代碼。
paragraphs = re.findall(r'[Scene: [ws,]+.]s([^[]+)s(?=[Scene: [ws,]+.])', a, re.S)
python正則表達式指南http://www.cnblogs.com/huxi/a...
相關文章:
1. html5和Flash對抗是什么情況?2. html5 - datatables 加載不出來數據。3. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????4. 利用IPMI遠程安裝centos報錯!5. node.js - mongodb查找子對象的名稱為某個值的對象的方法6. 運行python程序時出現“應用程序發生異常”的內存錯誤?7. 測試自動化html元素選擇器元素ID或DataAttribute [關閉]8. javascript - QQ第三方登錄的問題9. javascript - 在 model里定義的 引用表模型時,model為undefined。10. spring-mvc - spring-session-redis HttpSessionListener失效

網公網安備