extract string using same pattern in a text using R

前端 未结 2 1438
-上瘾入骨i
-上瘾入骨i 2021-01-24 07:46

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.


        
相关标签:
2条回答
  • 2021-01-24 08:15

    You could use regex to look for results that match text between two hashes that don't contain a space character.

    Something like this: ([#]{1}[^\s]+[#]{1})

    0 讨论(0)
  • 2021-01-24 08:25

    We can do

    str_extract_all(text, "(?<=#)\\w*(?=#)")[[1]]
    #[1] "Pray4Manchester" "ArianaGrande"   
    

    data

    text <- "#Pray4Manchester# I hope that #ArianaGrande# will be better soon."
    
    0 讨论(0)
提交回复
热议问题