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,如上,我想取得每個(gè)場(chǎng)景的對(duì)話文本,保存成lsit,每個(gè)場(chǎng)景的區(qū)分是[Scene: 加一句英文.],如上面加粗的部分然后用正則表達(dá)式寫,paragraphs = re.findall(’[Scene: w+.](.*?)[Scene: w+.]’,a,re.S)
我發(fā)現(xiàn)沒有匹配出內(nèi)容來,paragraphs是個(gè)空的,請(qǐng)問錯(cuò)誤的原因在哪,該如何去匹配每一場(chǎng)景的對(duì)話內(nèi)容?謝謝。
問題解答
回答1:錯(cuò)誤有幾點(diǎn)沒有使用原生字符串沒有轉(zhuǎn)義[
以下是我修改后的代碼。
paragraphs = re.findall(r'[Scene: [ws,]+.]s([^[]+)s(?=[Scene: [ws,]+.])', a, re.S)
python正則表達(dá)式指南http://www.cnblogs.com/huxi/a...
相關(guān)文章:
1. python - 獲取到的數(shù)據(jù)生成新的mysql表2. javascript - js 對(duì)中文進(jìn)行MD5加密和python結(jié)果不一樣。3. mysql里的大表用mycat做水平拆分,是不是要先手動(dòng)分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. sass - gem install compass 使用淘寶 Ruby 安裝失敗,出現(xiàn) 4046. python - (初學(xué)者)代碼運(yùn)行不起來,求指導(dǎo),謝謝!7. 為啥不用HBuilder?8. python - flask sqlalchemy signals 無法觸發(fā)9. python的文件讀寫問題?10. 為什么python中實(shí)例檢查推薦使用isinstance而不是type?
