简体   繁体   中英

how to extract string after some desired letters? using python 2.0 and numpy and pandas only

如何在“您参加了”之后提取字符串?

"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)?"

We could try just using split here, for a non regex option:

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)

This prints:

Hazza bin Zayed Stadium (Al Ain)?

Try using regex:

>>> 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)?'
>>> 

Or use:

>>> 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 could use regex:

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

You would be after the only group in the only match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM