量词正则表达式{n}-完全匹配-在R中不起作用

时间:2019-11-06 19:48:36

标签: r regex

我有以下变量:

x <- c('Homer Simpsom', 'Homer Three')

我仅将此函数用于提取Homer Simpsom(量化词{7}):

library(tidyverse)

str_subset(string = x, regex(pattern = '(?<=Homer)\\s\\w{7}'))

[1] "Homer Simpsom"

结果正常。但是,不适用于Homer Three(量化器{5}):

str_subset(string = x, regex(pattern = '(?<=Homer)\\s\\w{5}'))

[1] "Homer Simpsom" "Homer Three"

我知道Follow函数起作用:

str_subset(string = x, regex(pattern = '(?<=Homer)\\s\\w{5}$'))

[1] "Homer Three"

但是,为什么仅{5}(没有$)不起作用?

0 个答案:

没有答案