当前位置:首页 » 编程语言 » java取数

java取数

发布时间: 2023-03-06 16:24:43

java如何从字符串中提取数字

使用正则表达式可以很方便地从文本中截取数字,下面是详细代码:
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
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("");
}
}

热点内容
二手车宝马320li17年有哪些配置 发布:2025-09-16 17:59:32 浏览:888
c语言n次方怎么输入 发布:2025-09-16 17:51:17 浏览:909
完美国际密码在哪里改 发布:2025-09-16 17:43:44 浏览:907
网盘解压包怎么打开 发布:2025-09-16 16:59:19 浏览:816
红火脚本 发布:2025-09-16 16:53:21 浏览:987
centosphp56 发布:2025-09-16 16:52:24 浏览:256
修改逃跑吧少年不用找脚本 发布:2025-09-16 16:50:43 浏览:144
php慢日志 发布:2025-09-16 16:44:46 浏览:310
什么电脑配置做pr比较顺畅 发布:2025-09-16 16:42:03 浏览:298
centosphprpm 发布:2025-09-16 16:40:34 浏览:148