我正在尝试以下操作:
gg <-c("delete from below 110 11031133 11 11031135 110",
"delete froml #10989431 from adfdaf 10888022 <(>&<)> 10888018",
"this is for the deletion of an incorrect numberss that is no longer used for asd09 and sd040",
"please delete the following mangoes from trey 10246211 1 10821224 1 10821248 1 10821249",
"from 11015647 helppp 1 na from 0050 - zfhhhh 10840637 1")
pattern_to_find <- c('\d{4,}')
aa <- str_extract_all(gg, pattern_to_find)
aa
有了这段代码,我可以extact任何数字大于固定数字的数字模式。但如果我想提取2个didit数字,那么它会从数字字段中提取所有前两个数字。
pattern_to_find <- c('\d{2}').
How can I modify my pattern to work on both ways.
Regards,
R
Tidyverse解决方案:
library(tidyverse)
pattern_to_find <- c('\d{2,}')
aa <- str_extract_all(gg, pattern_to_find)
基本R解决方案:
base_aa <- regmatches(gg, gregexpr(pattern_to_find, gg))