R 中级正则表达式
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 中级正则表达式