【问题标题】:Removing first alphabetic character from string从字符串中删除第一个字母字符
【发布时间】:2019-07-30 22:13:45
【问题描述】:

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

数据外观示例: Z999999999 12ABC 123456AB7

我希望数据是什么样的: 999999999 12ABC 123456AB7

【问题讨论】:

  • 您尝试了哪些方法,在哪里遇到了问题?加粗的字母是否需要保留为粗体?你期望输出在哪里?
  • 如果字符串开头有两个字母字符怎么办?您是同时删除两个还是只删除第一个?

标签: r regex excel


【解决方案1】:

你需要使用正则表达式

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

阅读:

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

【讨论】:

    【解决方案2】:
    library(stringr)
    x <- 'Z999999999 12ABC 123456AB7'
    str_replace(x, '^[a-zA-Z]','') # find a leading letter and replace it with nothing
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多