import Foundation
let pattern = #"(?!0)\d+[\u4e00-\u9fa5、/()()]+([\u4e00-\u9fa5])"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
民事公益诉讼起诉率=((200民事公益诉讼起诉案件数(件)+民事公益诉讼两支案件数(件))/(201民事公益诉讼立案案件数(件)+民事公益诉讼立案积存数(件)))*100%
检管平台数据+人工(政务内网2.0案件数据)
39开展追赃挽损工作率=(37经济类、侵财类犯罪案件中检察机关开展追赃挽损工作(件))/38经济类、侵财类犯罪案件审结数(件))*100%
87被刑事申诉纠正率=((250经申诉被改变原逮捕/不捕决定数(人)+251经申诉被改变原起诉/不起诉决定数(人))/86刑事申诉案件审结(人))*100%
民事案-件比=7件数/8案数
181行政执行(含非诉执行)监督检察建议采纳率=(179行政执行(含非诉执行)监督案件检察建议采纳数(件)/180行政执行(含非诉执行)监督案件检察建议数(件))*100%
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let matches = regex.matches(in: testString, range: stringRange)
var result: [[String]] = []
for match in matches {
var groups: [String] = []
for rangeIndex in 1 ..< match.numberOfRanges {
let nsRange = match.range(at: rangeIndex)
guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue }
let string = (testString as NSString).substring(with: nsRange)
groups.append(string)
}
if !groups.isEmpty {
result.append(groups)
}
}
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression