R 中級 Regular Expressions
Angelo Zehr
Data Journalist
「…到了店裡。體驗超級順暢無縫,物超所值。我非常推薦 ABC Enterprises,而且我一定會再回來!接著我們…」
一個單字:(\\w+\\s),0 到 10 個單字:(\\w+\\s){0,10}
str_extract_all(
blog_post,
pattern = "(\\w+\\s){0,10}ABC Enterprises\\s?(\\w+\\s){0,10}"
)
回傳:
"I would highly recommend ABC Enterprises and I will be coming back for"
「…到了店裡。體驗超級順暢無縫,物超所值。我非常推薦 ABC Enterprises,而且我一定會再回來!接著我們…」
擷取結果:
"I would highly recommend ABC Enterprises and I will be coming back for"
將 \\w+ 換成 [\\w[:punct:]]+
擷取結果:
"smooth and seamless experience. Great value. I would highly recommend ABC Enterprises and I will be coming back for sure! Next, we "
R 中級 Regular Expressions