我想拿起后面跟着两个数字的模式mn。
我的文本是:
apple 20127041 needs the following changes from ab34 to mn35-f01 priority - mn43 mn56.预期输出为mn43和mn56。它不应该拾取mn35-
我不能否定-。
dd <- c("apple 20127041 needs the following changes from ab34 to mn35-f01 priority - mn43 mn56 ")
str_extract_all(dd,'\\bmn[0-9]{2}\\b')它的价值也在回升。
发布于 2020-05-13 17:07:54
在(?!-)之前添加一个非消耗性的负面展望
stringr::str_extract_all(dd,'\\bmn[0-9]{2}\\b(?!-)')
#[1] "mn43" "mn56"发布于 2020-05-13 17:10:05
str_extract_all(dd,'mn[0-9]{2}[^-]')
[[1]]
[1] "mn43 " "mn56 "从允许出现在数字后面的字符中排除-。要去掉空格,请使用trimws和unlist
trimws(unlist(str_extract_all(dd,'mn[0-9]{2}[^-]')))
[1] "mn43" "mn56"https://stackoverflow.com/questions/61770455
复制相似问题