我目前正在开发光学字符识别(OCR)应用程序,它会将名片中的已识别数据传递给联系人。我已经从名片中设法recognized the data。
问题是如何在该文本框中识别电话号码等内容并将其传递到phone contact textfield?
答案 0 :(得分:1)
你可以试试这个:
String text = "This is the text 2432423 which contains phone numbers 56565555";
Pattern pattern = Pattern.compile("\\d{5,12}"); // at least 5 at most 12
// before match remove all the spaces, to ensure the length on numbers is OK it will work more better.
Matcher matcher = pattern.matcher(text.replaceAll(" ", ""));
while (matcher.find()) {
String num = matcher.group();
System.out.println("phone = " + num);
}
这就是输出:
phone = 2432423
phone = 56565555
注意:至少并且最多可以根据您的要求进行更改。