国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

python特定段落的文本匹配

瀏覽:115日期:2022-07-08 13:43:26

問題描述

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...

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 云阳县| 治多县| 岳普湖县| 宁都县| 灵宝市| 普兰店市| 泾阳县| 喀喇沁旗| 廉江市| 道孚县| 东乡| 米易县| 三门县| 中江县| 鸡泽县| 河源市| 隆尧县| 盱眙县| 泊头市| 安徽省| 永福县| 大足县| 临沧市| 邳州市| 苍山县| 南川市| 浦东新区| 惠安县| 敖汉旗| 丹东市| 新河县| 弋阳县| 海晏县| 大理市| 和静县| 江山市| 荆门市| 安仁县| 山阳县| 澎湖县| 娄烦县|