【问题标题】:How to remove unicode <U+2032> from string? [duplicate]如何从字符串中删除 unicode <U+2032>? [复制]
【发布时间】:2016-11-28 19:30:49
【问题描述】:

我用过this method,但它不起作用。 我的代码包含如下值:

clients <- c("Greg Smith <U+2032>", "John Coolman", "Mr. Brown <U+2032>")

所以我尝试了:

clients <- gsub("$\\s*<U\\+\\w+>", "", clients)

但它不起作用。

【问题讨论】:

  • gsub(" &lt;[^&gt;]+&gt;", "", clients)?

标签: r regex


【解决方案1】:
clients <- gsub("[<].*[>]", "", clients)

【讨论】:

    【解决方案2】:

    您将$ 作为表达式的第一个字符。这匹配表达式的结尾,但前提是它是模式的最后一个字符:

    > gsub("\\s*<U\\+\\w+>$", "", clients)
    [1] "Greg Smith"   "John Coolman" "Mr. Brown"  
    

    【讨论】:

      【解决方案3】:

      如果您只想删除 unicode &lt;U+2032&gt;

      clients <- c("Greg Smith <U+2032>", "John Coolman", "Mr. Brown <U+2032>")
      clients <- gsub("<U\\+2032>", "", clients)
      clients
      # [1] "Greg Smith "   "John Coolman" "Mr. Brown "
      

      【讨论】:

        猜你喜欢
        • 2017-02-20
        • 2019-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多