|
楼主 |
发表于 2019-3-28 12:42:10
|
显示全部楼层
import re
str_speaker_content_1 = 'Yesterday, I visited Sirs Andrew and Nancy I asked Sir Andrew who he was, and he answered impatiently: "Sir Nancy and I are Knaves" Then I met Sir Bill who introduced me to his wife and told me: "at least one of Sir Hilary and I is a Knave" Should I trust them'
pattern = re.compile('"([^"]+)"')
str_speaker_content_1 = str_speaker_content_1.replace(',','')
str_speaker_content_2 = pattern.findall(str_speaker_content_1) #findall在字符串中找到正则表达式所匹配的所有子串,并组成一个列表返回
print(str_speaker_content_2[0]) #提取双引号 “” 内的数据
那像这个,如果我加太多的话, 这个列表的值就会说超出范围了 - - |
|