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. javascript - jquery怎么給select option一個點擊時觸發的事件,如圖 如果選擇自定義觸發一個時間?2. javascript - 怎樣限制同一個瀏覽器不能登錄兩個賬號3. nginx配置server模塊的問題4. java - android代碼重構:如何把app設置里的頭像UI做成通用的?5. 想找個php大神仿個網站。6. java - 新手做一個安卓視頻播放器,想實現一個進度條,按鈕那種在視頻下方懸浮的功能,不知道思路!7. javascript - angular和jquery都用到了$符號,一起用會不會沖突?8. css3 - Typecho 后臺部分表單按鈕在 Chrome 下出現靈異動畫問題,求解決9. mysql優化 - 關于mysql分區10. 如何將行內塊元素的內容垂直水平兩個方向居中?
