![](/img/trans.png)
[英]R regex / grep / grepl for letters followed by a dash and numbers
[英]Using R Regex to identify two characters followed by a dash and two numbers
非常讨厌的正则表达式问题传入。 我有一个列,我试图根据一个条件将其分成两列,我希望在有两个字符时创建一个新列。 后跟一个破折号和两个数字(例如, CA-01
)。
我的代码是:
mydf %>% extract(col = pilot_id, regex = "[az]{2}.d{2}", into = 'facility_test')
我想在其中识别模式的列是pilot_id
,而我想创建的新列是facility_test
。
我们需要在extract
中捕获
library(dplyr)
library(tidyr)
mydf %>%
extract(col = pilot_id, regex = ".*-([A-Z]{2}-\\d{2})\\s.*",
into = 'facility_test')
# A tibble: 1 x 1
# facility_test
# <chr>
#1 FL-03
mydf <- tibble(pilot_id = "TGT Track -FL-03 (Hilsborough County) 3/3/2021")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.