java正则表达式提取数字的方法实例
更新时间:2013年12月19日 09:42:35 作者:
这篇文章主要介绍了java正则表达式提取数字的方法,还有去除字符串数字的方法,大家参考使用吧
复制代码 代码如下:
@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());
}
相关文章
解决springboot整合cxf-jaxrs中json转换的问题
这篇文章主要介绍了解决springboot整合cxf-jaxrs中json转换的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2021-07-07Mybatis selectKey 如何返回新增用户的id值
这篇文章主要介绍了Mybatis selectKey 如何返回新增用户的id值,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-01-01IDEA配置静态资源热加载操作(Springboot修改静态资源不重启)
这篇文章主要介绍了IDEA配置静态资源热加载操作(Springboot修改静态资源不重启),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-10-10详解MyBatis的getMapper()接口、resultMap标签、Alias别名、 尽量提取sql列、动态操作
这篇文章主要介绍了详解MyBatis的getMapper()接口、resultMap标签、Alias别名、 尽量提取sql列、动态操作的相关资料,需要的朋友可以参考下2016-08-08
最新评论