Let's assume I have some string like that:
x = 'Wish she could have told me herself. @NicoleScherzy #nicolescherzinger #OneLove #myfav #MyQueen :heavy_black_heart::heavy_black_heart: some string too :smiling_face:'
So, I want to get from that :
:heavy_black_heart:
:smiling_face:
To do that I did the following :
import re
result = re.search(':(.*?):', x)
result.group()
It only gives me the ':heavy_black_heart:' . How could I make it work ? If possible I want to store them in dictonary after I found all of them.
set(re.findall(r':[^:]+:', x))will do? Not sure what there might be between:, mayber':\w+:'will work better.::? As I said, you did not post exact specs. If you need to match any chars inside:...:that are not whitespaces, use:[^\s:]+:- see my updated answer.