I'm trying to deal with text with R and here is my question.
From this source text
#Pray4Manchester# I hope that #ArianaGrande# will be better soon.
I want to extract Pray4Manchester and ArianaGrande using the pattern #.+#, but when I run
str_extract_all(text,pattern="#.+#")
I get
#Pray4Manchester# I hope that #ArianaGrande#
How to solve this? Thanks.
#also matches pattern.+, and this (I guess) causesstr_extractto look greedily for widest match. You will need pattern that does not include#in itself, such as the one suggested by akrun, for example.str_extract_all(text,pattern="#.+?#")