有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android中Telugu字符串的java正则表达式?

我能够从OCR结果中获取以下Telugu字符串。我需要为该字符串应用正则表达式。有人能帮我查一下性别、姓名、地址吗

customStr = "డివిజన్‌: షాద్‌ నగర్‌\n(గ్రామం: వెలిజర్ల -1\n\n \n  \n \n\n \n\n \n\n||\n\n(|\n\n|||\n\n|||\n\nఖాతానెం.: 783\n\n  \n\n' 1. పట్టాదారు పేరు ఇంటిపేరుతో : చతుర్వేదుల భార్గవి\n., 2. తండ్రి / భర్తపేరు : శ్రీధర కేదార్‌ నాథ్‌\n\n౩. స్త్రీ / పురుషుడు : Female\n, 4. చిరునామా : వెలిజర్ల -1\n5. కులము : General\n6. ఆధార్‌ సంఖ్య : XXXXXXXX8381\n\n7. పట్టాదారు సంతకం ఎడమ /కుడి చేతి వేలిముద్ర\n\nతహశీల్దార్‌ సంత!\n\n \n\nith CamScanner"

我正在使用以下源代码,但没有结果

String[] lines = customStr.split("\\r?\\n", -1);

        for(String line : lines) {



                if (customStr.contains("స్త్రీ / పురుషుడు")){
                    text4.setText(line);
                }
                else{
                    System.out.printf("ok");
                }

            }

共 (1) 个答案

  1. # 1 楼答案

    使用带有模式和匹配器的正则表达式获取性别、姓名和地址。 请参考以下示例:

        Pattern genderPattern = Pattern.compile("౩. స్త్రీ / పురుషుడు : (.*?)\n,");
        Pattern addressPattern = Pattern.compile("4. చిరునామా : (.*?)\n5.");
        Pattern namePattern  = Pattern.compile("1. పట్టాదారు పేరు ఇంటిపేరుతో : (.*?)\n.,");
        Matcher m;
        m=genderPattern.matcher(customStr);
        if(m.find())
            gender = m.group(1));
        m=addressPattern.matcher(customStr);
        if(m.find())
            address = m.group(1));
        m=namePattern.matcher(customStr);
        if(m.find())
            name = m.group(1));