c# - Check text for multiple RegEx matches -
the code below reads in text (scanned ocr library) checks text few simple words "the", "date", "or", "to", "and".... if finds 1 of words function returns true >>> meaning page scan turned correct way. if function returns false, page upside down , moves function rotates page.
i'm trying figure out best way this. i'm not regex master, first if statement comes true (so finds 'date'). however, second if statement comes false though i'm looking 'date' again.
do conditional or ||
not work regex?
static boolean checkifpdfisturnedrightway(list<tessnet2.word> wordlist) { if (wordlist.count >= 70) { var text = wordlist.select(w => w.confidence >= 40 ? w.text : "dontmatch").aggregate((x, y) => x + " " + y); if (!regex.ismatch(text, @"date", regexoptions.ignorecase)) return false; if (!regex.ismatch(text, @"[trf]h[ec]", regexoptions.ignorecase) | !regex.ismatch(text, @"date", regexoptions.ignorecase) || !regex.ismatch(text, @"[a0o][tfr]", regexoptions.ignorecase) || !regex.ismatch(text, @"[ao]nd", regexoptions.ignorecase) || !regex.ismatch(text, @"[frt][o0]", regexoptions.ignorecase)) return false; } return true; }
ismatch
returns boolean, should able use ||
.
you may have typo. check out single pipe between first 2 !regex.ismatch
statements:
if (!regex.ismatch(text, @"[trf]h[ec]", regexoptions.ignorecase) | !regex.ismatch(text, @"date", regexoptions.ignorecase) || ...
also, if want return false
if none of expressions in second if statement match, want use &&
operator instead.
if ((text doesn't match 1st expression) , (text doesn't match 2nd expr) , ... ) return false;
Comments
Post a Comment