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. docker绑定了nginx端口 外部访问不到2. Java中main方法里面的参数一定要是String []args吗?3. javascript - node.js中stat() access() open() readFile()都能判断文件是否存在?4. html5 - 目前 公司App 嵌入H5页面 做个 手机支付功能 没有做过 所以 请求各位有经验的 给个思路5. css - 如何讓圖片像雲一樣的行為?6. font-family - 我引入CSS3自定义字体没有效果?7. node.js - Nodejs微信开发,视频上传成功,但是不返回给用户8. javascript - js 多维数组的问题9. CSS3可否做出这个效果?10. mysql - sql 左连接结果union右连接结果,导致重复性计算怎么解决?
![Java中main方法里面的参数一定要是String []args吗?](http://www.haobala.com/attached/image/16.jpg)
网公网安备