从文本中提取匹配及其周边

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"

R 中级正则表达式

标点符号

"...到了商店。流程非常顺畅、无缝。性价比高。我强烈推荐 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 中级正则表达式

让我们来练习!

R 中级正则表达式

Preparing Video For Download...