我目前正在开发一个光学字符识别(OCR)应用程序,它将被识别的数据从名片传递到接触器中,我已经设法从名片中获得了识别数据。
问题是如何识别文本框中的电话号码等内容,并将其传递给电话联系人文本字段?
发布于 2015-12-25 02:14:23
你可以试试这个:
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
备注:至少最多也可以根据您的需求进行更改。
https://stackoverflow.com/questions/34459415
复制相似问题