I'm working on this script that uses the OCR library to read an image and then alert the matching text using the (text.match) method so this is the code:-
function readfile() {
Tesseract.recognize(
'form.png',
'ara',
{ logger: m => console.log(m) }
).then(({ data: { text } }) => {
console.log(text); /* this line here */
const info = ['نقطة الخدمة','رقم العداد','القراءة'];
for(k=0;k<info.length;k++){
var result = text.match(new RegExp(info[k] + '\\s+(\\w+)'))[1];
alert(result);
}
}) };
the code is only alerting the number that comes after the word ['القراءة'] but the other numbers after both words ['نقطة الخدمة','رقم العداد'] don't get alerted as you can see I'm logging the hole text to ensure that the library Tesseract doesn't fail to detect some Arabic letters as they are so this is the output :-
نقطة الخدمة 200135644
نوع الاستهلاك 0 رقم العداد 7038842 ١ القراءة 95808 تاريخها 05/04/2022
the image (form.png):-