I am using Swift 3 and trying to access captured groups.
let regexp = "((ALREADY PAID | NOT ALR | PROVIDER MAY | READY | MAY BILL | BILL YOU | PAID)((.|\\n)*))(( \\d+)(\\.+|-+)(\\d\\d))"
// check if some substring is in the recognized text
if let range = stringText.range(of:regexp, options: .regularExpression) {
let result = tesseract.recognizedText.substring(with:range)
}
I want to be able to extract out the last two numbers captured (\d\d
) so if the text was: ALREADY PAID asfasdfadsfasdf 39.15
, it would extract 15
. Here is a regex builder that shows what I want. Normally, I would be able to do $8
to get the 8th group that was extracted but I don't know how to do that in Swift 3.
(.|\\n)*
, just use.*
and add a(?s)
at the pattern start (or use the corresponding flag). – SyncytiumrangeAt(...)
. Examples here: https://mcmap.net/q/537748/-optional-capture-groups-with-nsregularexpressions-in-swift and here: https://mcmap.net/q/23817/-swift-extract-regex-matches and here: https://mcmap.net/q/537749/-how-to-parse-a-string-of-hex-into-ascii-equivalent-in-swift-2 – Medallist