【发布时间】:2017-08-05 00:32:48
【问题描述】:
我正在使用 Swift 3 并尝试访问捕获的组。
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)
}
我希望能够提取捕获的最后两个数字 (\d\d),因此如果文本是:ALREADY PAID asfasdfadsfasdf 39.15,它将提取 15。这是一个显示我想要的正则表达式生成器。通常,我可以使用$8 来获取第 8 组被提取的信息,但我不知道如何在 Swift 3 中执行此操作。
【问题讨论】:
-
永远不要使用
(.|\\n)*,只需使用.*并在模式开始处添加(?s)(或使用相应的标志)。