Reputation: 11
Im wanting to pull out a "thank you!" from this string, this is my code so far
tweet = ("Twitter,Thank you!,11-15-2017 10:58:18,96,433,false,9307")
import re
twt = ""
twt = re.findall(r',(.*?),',tweet)
print(twt)
this is my output
['Thank you!', '96', 'false']
im not sure why im not only getting "Thank you!"
Upvotes: 1
Views: 35
Reputation: 5543
You're using re.findall
which is giving you all the matches, you can use re.search
instead:
tweet = ("Twitter,Thank you!,11-15-2017 10:58:18,96,433,false,9307")
import re
twt = ""
twt = re.search(r',(.*?),',tweet).group(1)
>>> print(twt)
>>> 'Thank you!'
Upvotes: 2