加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java正则表达式提取数字的方法实例

发布时间:2020-12-14 05:19:16 所属栏目:Java 来源:网络整理
导读:复制代码 代码如下: @Test public void test33() { String phoneString = "哈哈,13888889999"; // 提取数字 // 1 Pattern pattern = Pattern.compile("[^0-9]"); Matcher matcher = pattern.matcher(phoneString); String all = matcher.replaceAll(""); Sys

复制代码 代码如下:

@Test
    public void test33() {
        String phoneString = "哈哈,13888889999";
        // 提取数字
        // 1
        Pattern pattern = Pattern.compile("[^0-9]");
        Matcher matcher = pattern.matcher(phoneString);
        String all = matcher.replaceAll("");
        System.out.println("phone:" + all);
        // 2
        Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
    }

 提取张三,去除数字

复制代码 代码如下:

@Test
    public void test() {
        // 提取张三 去除数字
        String r_name3 = "张三 13599998888 000000";
        Pattern pattern = Pattern.compile("[d]");
        Matcher matcher = pattern.matcher(r_name3);
        System.out.println(matcher.replaceAll("").trim());
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读