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. php - 微信開發(fā)驗(yàn)證服務(wù)器有效性2. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過段時(shí)間會(huì)消失是什么情況?3. javascript - 我的站點(diǎn)貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?4. mysql - 請(qǐng)問數(shù)據(jù)庫(kù)字段為年月日,傳進(jìn)的參數(shù)為月,怎么查詢那個(gè)月所對(duì)應(yīng)的數(shù)據(jù)5. Python2中code.co_kwonlyargcount的等效寫法6. python - 如何判斷字符串為企業(yè)注冊(cè)名稱7. html - 移動(dòng)端radio無法選中8. javascript - vue+iview upload傳參失敗 跨域問題后臺(tái)已經(jīng)解決 仍然報(bào)403,這是怎么回事啊?9. [python2]local variable referenced before assignment問題10. python中怎么對(duì)列表以區(qū)間進(jìn)行統(tǒng)計(jì)?
