[英]Function for regular expression in R
I need to extract certain sequences from a string of text.我需要从一串文本中提取某些序列。 Something like 93085k82 will be embedded in text.
诸如 93085k82 之类的东西将被嵌入到文本中。 Is there a script that identify when 5 numbers, a letter, and then 2 numbers occur?
是否有脚本可以识别何时出现 5 个数字、一个字母和 2 个数字?
We can use pattern starting with word boundary ( \\\\b
) followed by five digits ( \\\\d{5}
), a lower case letter ( [az]{1}
) and two digits ( \\\\d{2}
) followed by the word boundary ( \\\\b
)我们可以使用以单词边界 (
\\\\b
) 开头的模式,后跟五个数字 ( \\\\d{5}
)、一个小写字母 ( [az]{1}
) 和两个数字 ( \\\\d{2}
)通过单词边界( \\\\b
)
grep("\\b\\d{5}[a-z]{1}\\d{2}\\b", v1)
If we need to extract如果我们需要提取
library(stringr)
str_extract_all(v1, "\\b\\d{5}[a-z]{1}\\d{2}\\b")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.