用于整数的带String.match()的Java正则表达式

用于整数的带String.match()的Java正则表达式,java,android,regex,pattern-matching,android-vision,Java,Android,Regex,Pattern Matching,Android Vision,我正试图从我的OCR文本检测器中获取某些数字。 到目前为止,我还没有成功地提取出这些数字 以某种形式。 该数字看起来与此5225612832654459相似 通常,格式可以是这样的XXXXXXXXXXXX 我需要一个字符串匹配正则表达式来获得这样一个数字。 注意:我需要避免捕捉图片来源中的其他数字 这里是方法 List<? extends Text> textComponents = text.getComponents(); for (Text currentText : text

我正试图从我的OCR文本检测器中获取某些数字。 到目前为止,我还没有成功地提取出这些数字 以某种形式。 该数字看起来与此5225612832654459相似 通常,格式可以是这样的XXXXXXXXXXXX

我需要一个字符串匹配正则表达式来获得这样一个数字。 注意:我需要避免捕捉图片来源中的其他数字 这里是方法

List<? extends Text> textComponents = text.getComponents();
for (Text currentText : textComponents) {
    float left = translateX(currentText.getBoundingBox().left);
    float bottom = translateY(currentText.getBoundingBox().bottom);
    canvas.drawText(currentText.getValue(),left,bottom,sTectPaint);

    // get certain type of text
    if(currentText !=null && currentText.getValue() != null) {
        if (currentText.getValue().matches("^[0-9]+(0-9]+[0-9]+[0-9]") || currentText.getValue().contains("0123456789")) {
            Log.e("number", currentText.getValue());
            myNum = "";
            myNum = currentText.getValue();
        }
    }
}                 

List类似的东西?这将匹配4组,每组正好4个数字,用空格分隔:

public static void main (String[] args) throws java.lang.Exception
{
    System.out.println(matches("1234 5678 1234 9872"));
    System.out.println(matches("1234 5678 1234 9872 3265"));
    System.out.println(matches("134 5678 1234 9872"));
    System.out.println(matches("1234 5678 14 982"));
    System.out.println(matches("1234"));
    System.out.println(matches("1234 5678 12345 9872"));
}

private static boolean matches(String text) {
    return text.matches("^\\d{4} \\d{4} \\d{4} \\d{4}");
}
输出:

true
false
false
false
false
false

不过,根据您输入的内容,您可能需要稍微修改正则表达式。

问题出在哪里?这是信用卡号吗?谢谢您的帮助