Python text matching for specific paragraphs
PHP中文网
PHP中文网 2017-05-18 10:57:26
0
1
710

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

I have a text a, as above,
I want to get the dialogue text of each scene and save it as lsit. The difference between each scene is [Scene: Add an English sentence.], as shown in bold# above ##Then use regular expressions to write,
paragraphs = re.findall('[Scene: w .](.*?)[Scene: w .]',a,re.S)

I found that there was no matching content, and paragraphs was empty.

What is the reason for the error? How to match the dialogue content of each scene?
Thanks.

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
滿天的星座

There are several errors
No native string is used
No escaping[

The following is my modified code.

paragraphs = re.findall(r"\[Scene: [\w\s,]+\.]\s([^[]+)\s(?=\[Scene: [\w\s,]+\.])", a, re.S)

Python regular expression guide
http://www.cnblogs.com/huxi/a...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!