regex 编写正则表达式来替换日期模式

fzsnzjdm  于 2023-01-31  发布在  其他
关注(0)|答案(1)|浏览(172)

我的数据中有一个模式,以月份的三个字母开头,后面的一个或两个数字表示月份中的某一天。这是数据的快照

df_new <- data.frame(
   given_info=c('oct12 is given','he received on jan1',
                'lets go on dec12','also feb04 is right'))
 
 df_new %>% select(given_info)
           given_info
1      oct12 is given
2 he received on jan1
3    lets go on dec12
4 also feb04 is right

我需要找到正则表达式来捕获这些项,并将其替换为specific time这样的项。因此,所需的结果如下:

given_info
1      specific timeis given
2     he received on specific time
3    lets fo on specific time
4    also specific timeis right

太感谢你了!

7kqas0il

7kqas0il1#

gsub("\\b[a-z]{3}[0-9]{2}\\b", "specific time", df_new$given_info)
# [1] "specific time is given"      "he received on jan1"         "lets go on specific time"    "also specific time is right"

相关问题