I am using OCR on a receipt reading app I'm building. Understandably the OCR struggles differing between an S and a 5.
My app finds each line in a restaurant receipt normally formatted like below:
1 Champagne £505.55
5 Burger with chips £25.00
2 Chips with cheese £5.00
2 Coke £1.50
1 Ketchup £0.50
5 Penny sweets £0.05
Currently I can find the Int and the text fine, I can also get the double at the end too but rarely if it contains a five. Is there some regex that I can put in place to determine if a 5 has been replaced by looking at its surroundings? I can only assume at the moment by recognising the currency symbol and replacing any occurrences after that? but sometimes it struggles to recognise those or there isn't one. Any suggestions or help would be great. Thanks
edit: I understand there may not be a perfect answer to get tough prices like £555.55 that appears as SSS.SS but if there is something for the more commom prices like 0.50, 10.50 or 5.00 etc id love to hear some suggestions. Thanks again
Update:
mutating func replaceWhereFivesShouldBe() {
do {
let regEx = try! NSRegularExpression(pattern: "\\s+[0-9S]+\\.[0-9S]{2}")
let range = NSMakeRange(0, self.characters.count)
self = regEx.stringByReplacingMatches(in: self, range: range, withTemplate: "5")
} catch {
return
}
}