我有以下变量:
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}
(没有$
)不起作用?