如何在所需字母后提取字符串?仅使用python2.0和numpy和pandas

2024-09-30 08:29:27 发布

您现在位置:Python中文网/ 问答频道 /正文

如何提取“you attent at the”后面的字符串?你知道吗

"How satisfied, if at all, are you with the following stadium facilities at the Arabian Gulf League/Arabian Cup/Arabian Super Cup/President's Cup matches you attend at the Hazza bin Zayed Stadium (Al Ain)?"

Tags: the字符串youifwithallareat
3条回答

尝试使用正则表达式:

>>> import re
>>> re.sub('.*you attend at the ', '', "How satisfied, if at all, are you with the following stadium facilities at the Arabian Gulf League/Arabian Cup/Arabian Super Cup/President's Cup matches you attend at the Hazza bin Zayed Stadium (Al Ain)?")
'Hazza bin Zayed Stadium (Al Ain)?'
>>> 

或使用:

>>> s = "How satisfied, if at all, are you with the following stadium facilities at the Arabian Gulf League/Arabian Cup/Arabian Super Cup/President's Cup matches you attend at the Hazza bin Zayed Stadium (Al Ain)?"
>>> s[s.find("you attend at the ") + 18:]
'Hazza bin Zayed Stadium (Al Ain)?'
>>> 

你可以使用正则表达式:

(?:you attend at the )(.*)

你会在唯一的比赛中追上唯一的一组。你知道吗

我们可以在这里尝试使用split作为非regex选项:

inp = "How satisfied, if at all, are you with the following stadium facilities at the Arabian Gulf League/Arabian Cup/Arabian Super Cup/President's Cup matches you attend at the Hazza bin Zayed Stadium (Al Ain)?"
output = inp.split('you attend at the')[1]
print(output)

这张照片:

Hazza bin Zayed Stadium (Al Ain)?

相关问题 更多 >

    热门问题