在这里,我试图在关键字匹配后提取文本中的名称
Keywords = ['customer::name:', '- first name:', 'let me get you to a specialist. please tell us your first name', 'please tell us your first name']
如果字符串中出现任何关键字,则应在此处删除名称
excel数据是
str1=
- Selections: U-verse TV > HSC - Inline Auth Uverse
Mindy has left the chat
You are being transferred, please hold...
Customer::Name: jhon henry
str2=
Adam has left the chat
You are being transferred, please hold...
- First Name: jennatee
tGuard Information >> Wireless Number: TG_NOT_FOUND *** Wireless BAN: TG_NOT_FOUND
str3=
Agent::[virtualAssistant.nina]: <div onclick="window.inqFrame.Application.sendVALinkClicked(event);" >Let me get you to a specialist. Please tell us your first name.</div>
Customer::karl
Once the installation is done, you can expect to receive the e-mail notication regarding all the details.
str4=
Let me get you to a specialist.<br /><br /> Please tell us your first name.</div> *** Customer::Max canon *** Agent::[virtualAssistant.nina]: <div onclick="window.inqFrame.Application.sendVALinkClicked(even)
每个字符串的输出应如下所示,
对于str1,[出]:Jhon henry。
对于str2,[输出]:珍妮。
对于str3,[输出]:karl。
对于str4,[输出]:最大佳能。
我已经尝试过这种方法,但是没有解决。 如果我的代码与获取上述输出无关,请向我展示另一种解决方案。
str=[str1,str2,str3]
m=re.search(r'[customer::name:|first name|let me get you to a specialist. please tell us your first name|please tell us your first name]', str)
m.groups()
感谢和问候
答案 0 :(得分:0)
您可以尝试
#this pattern gives the next word after the match. You can add more match strings if you like
pattern=r'((?<=)(customer::name:|customer::|first name:|please tell us your first name)(.?\w+))'
print (re.findall(pattern,str.lower(string))[0][2])