简体   繁体   中英

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. Is there a script that identify when 5 numbers, a letter, and then 2 numbers occur?

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 )

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM