so have below method scan through list of words, finds "control number:" , sets wordnumber, sets next word controlnum (which string looking return).
public string absfindcontrolnumber(list<tessnet2.word> wordlist) { (int = 0; < wordlist.count; i++) { if (wordlist[i].text == "control number:" && wordlist[i].confidence >= 50) { string wordnumber = wordlist[i].text.tostring(); controlnum = wordlist[i + 1].text.tostring(); return controlnum; } } }
but after finding out how similar approach using regex. want see if there way set controlnum next word. have few different cases letters/numbers in case doesn't find exact word.
if (regex.ismatch(text, @"c(0|o)ntr(0|o)(l|1|i)\s+nu(in|m)ber(:|;|s)", regexoptions.ignorecase)) { controlnum = ??? }
you can this:
string text = "control number: 123foobar"; var match = regex.match(text, @"c[o0]ntr[o0][l1i]\s+nu(?:in|m)ber[:;s]\s*(\w*)", regexoptions.ignorecase); if (match.success) { var controlnum = match.groups[1].value; // 123foobar }
Comments
Post a Comment