正则表达式仅在 dplyr 中查找单词并跟随特殊字符/数字/点

问题描述 投票:0回答:0

希望这能很好地满足你。 我需要在文本中的任何位置找到那些包含术语

info
的行

  1. 前后无字符
  2. 后面跟一个点或任何特殊字符
  3. 跟随一个或多个数字

这是可以提供帮助的数据快照

df_new <- data.frame(
  text=c('info is given','he is given info. in the class',
               'she needs info2','why not having information',
               'his info# missing', 'info12 and packages are given',
               'parainfo is ready','info. was awarded',
               'meeting is with .info'))
> df_new
                            text
1                  info is given
2 he is given info. in the class
3                she needs info2
4     why not having information
5              his info# missing
6  info12 and packages are given
7              parainfo is ready
8              info. was awarded
9           meeting is with .info

因此,感兴趣的结果是:

                      text             strings_detected
                  info is given               1
 he is given info. in the class               1   
                she needs info2               1
     why not having information               0
              his info# missing               1
  info12 and packages are given               1
              parainfo is ready               0
              info. was awarded               1 
           meeting is with .info              0   
 

非常感谢!

regex dplyr text string-matching
© www.soinside.com 2019 - 2024. All rights reserved.