从字符串中提取电话号码 [英] Extracting phone number from string

查看:75
本文介绍了从字符串中提取电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从给定的字符串中提取Java中的电话号码,即电话号码可以在字符串中的任何位置,例如 [bla bla] TELEPHONE NUMBER [bla bla] .现在,我要提取这个电话号码放在另一个字符串中.

I am trying to extract phone number in java from the given String i.e. the phone number can be anywhere in the String like [bla bla]TELEPHONE NUMBER[bla bla].Now I want to extract this telephone number in another String.

使用

 matcher.matches()

它返回是真还是假,但我没有得到提取的电话号码.

it returns me true or false but I am not getting the phone number which it gets extracted.

推荐答案


Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*");
Matcher m = p.matcher("Testing123Testing");

if (m.find()) {
    System.out.println(m.group(1));
}

这篇关于从字符串中提取电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆