从字符串中删除第一个字母字符

时间:2019-07-30 22:13:45

标签: r regex excel

我有一列包含字母数字数据。我只想删除字母字符,除非它位于字符串的开头。

数据外观示例: Z 999999999 12 ABC 123456 AB 7

我希望数据看起来像什么: 999999999 12 ABC 123456 AB 7

2 个答案:

答案 0 :(得分:3)

您需要使用正则表达式

sub(pattern = "^[a-zA-Z]",replacement = "",x = "Z999999999 12ABC 123456AB7")

阅读:

https://www.rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf

答案 1 :(得分:2)

library(stringr)
x <- 'Z999999999 12ABC 123456AB7'
str_replace(x, '^[a-zA-Z]','') # find a leading letter and replace it with nothing