0

I need to verify hebrew text from the letter the letter's body like:

שלום,

תואם ייעוץ וידאו עם המטופל John Salivan. מועד הייעוץ נקבע לתאריך 23/02/2019 בשעה 20:45.

לביצוע הייעוץ יש להכנס

but my regex doesn't match text

    public static void findBadLines(String fileName) {

    Pattern regexp =  Pattern.compile(".*שלום,.*תואם ייעוץ וידאו עם המטופל John Salivan. .*מועד הייעוץ נקבע לתאריך .* בשעה.*..*לביצוע הייעוץ יש להכנס .*");
    Matcher matcher = regexp.matcher("");

    Path path = Paths.get(fileName);
    //another way of getting all the lines:
    //Files.readAllLines(path, ENCODING);
    try (
            BufferedReader reader = Files.newBufferedReader(path, ENCODING);
            LineNumberReader lineReader = new LineNumberReader(reader);
    ){
        String line = null;
        while ((line = lineReader.readLine()) != null) {
            matcher.reset(line); //reset the input
            if (!matcher.find()) {
                String msg = "Line " + lineReader.getLineNumber() + " is bad: " + line;
                throw new IllegalStateException(msg);
            }
        }
    }
    catch (IOException ex){
        ex.printStackTrace();
    }
}

final static Charset ENCODING = StandardCharsets.UTF_8;

}

Jorge Campos
  • 20,662
  • 7
  • 51
  • 77
kery
  • 11
  • 1
  • 5

1 Answers1

0

Do I get that right, you wan't to check if there is any hebrew text in a given input?

If so use that regex .*[\u0590-\u05ff]+.*

[\u0590-\u05ff]+ matches one or more hebrew characters, the .* before and after you need to match the rest of your input.

Respectively

   Pattern regexp =  Pattern.compile(".*[\u0590-\u05ff]+.*");
        //...
        matcher.reset(line); //reset the input
        if (!matcher.matches()) {
            String msg = "Line " + lineReader.getLineNumber() + " is bad: " + line;
            throw new IllegalStateException(msg);
        }
Shatterhand
  • 1
  • 1
  • 1
  • No, I need exactly verify all text- that body from the message contains correct text – kery Feb 24 '19 at 00:18