代码之家  ›  专栏  ›  技术社区  ›  Bitwise

从字符串中删除数值

  •  0
  • Bitwise  · 技术社区  · 7 年前

    如果给这个字符串 'Cool1, let's g3et to work' 如何返回此值 Cool, let's get to work 是吗?和Elixir在一起?

    到目前为止,我一直在尝试用没有锁的regex来实现这一点。

    2 回复  |  直到 6 年前
        1
  •  6
  •   davetapley    7 年前

    使用 String.replace 以下内容:

    String.replace("Cool1, let's g3et to work", ~r/\d/, "")
    

    这个 \d 方法 任何数字 (也称为数值)。

        2
  •  2
  •   chris    7 年前

    使用 Regex.replace 以下内容:

    Regex.replace(~r/\d/, "Cool1, let's g3et to work", "")