【问题标题】:Replace last characters of a string with its entire elements [duplicate]用整个元素替换字符串的最后一个字符[重复]
【发布时间】:2019-12-18 08:52:58
【问题描述】:

我的数据框中有一个要修改的元素。 我有一列具有以下类型的值

https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345

我想用最后 5 个字符替换整个字符串(即) 在这种情况下,将整个字符串替换为 12345。

我如何实现这一目标? 非常感谢。

【问题讨论】:

  • substr(string, nchar(string) - 4, nchar(string))
  • 工作正常。谢谢!

标签: r


【解决方案1】:

一种选择是使用a positive look behind 使用stringr::str_extract

str_extrct('https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345', 
           '(?<=proposalId\\=)\\d+')
#Simple option
str_extract('https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345', '\\d+')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2013-06-30
    • 2011-04-07
    • 1970-01-01
    • 2014-06-13
    • 2014-05-13
    • 1970-01-01
    相关资源
    最近更新 更多