Remove any digit only in first N characters

后端 未结 3 1946
攒了一身酷
攒了一身酷 2021-02-14 17:16

I\'m looking for a regular expression to catch all digits in the first 7 characters in a string.

This string has 12 characters:

A12B345CD678
         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-14 17:43

    The regex solution is cool, but I'd use something easier to read for maintainability. E.g.

    library(stringr)
    
    str_sub(s, 1, 7) = gsub('[A-Z]', '', str_sub(s, 1, 7))
    

提交回复
热议问题