import Foundation
let pattern = #"(?<=Overall Score ;).*(?= ;)"#
let regex = try! NSRegularExpression(pattern: pattern, options: .anchorsMatchLines)
let testString = #"""
1
"Simulator is not connected to SimNowlLink ;teports ;'ERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT, ;NOTES: ;IDemoUser ;Ring Rollercoaster 1 ;SCORE: ;26 ;88 ;DATE: 09/04/2020 08:20:36 ;Pay attention to all penalties. You ;can improve drops by following this ;advice: ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;SURGICAL' ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of ;Time to Complete ;Raw Value ;178.0 cm ;129.1 sec. ;50.0 ;50.0 ;Efficiency Subtotat ;Penalties ;Ring Collision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;Instrument-Endoscope Collisions ;Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Vatue ;13.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;2.0 ct. ;1.0 ct. ;Penalty Subtotal ;Overall Score ;pts. ;65.3 ;28.9 ;94 ;-1.3 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-4.0 ;-0.3 ;-6 ;88 ;k. ;
2
"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;IPtmoUser ;USE R?' ;Ring Rollercoaster 1 ;EXERCISE: ;ATT ÉivlPT ;27 ;DATE: 09/04/2020 ;SCORE BREAKDOWN', ;NOTES: ;Really focus on improving drops by ;following these ;0' handle grasped objectS ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;•j camera clutch to optimize your ;field of view. ;NCH €XERCISE ;INTUITIVE ;SURGICAL v ;SCORE: ;Raw Value ;177.7 cm ;143.4 sec. ;Efficiency hetrics ;Economy bf Åotion ;Time to Complete ;Penalties ;Efficiency Subtotal ;Ring Collision Warning (Yéllow) ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;instrument•Endoscope Collisions ;'Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;14.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.4 sec. ;3.0 ct. ;0.0 ct. ;Max Pts. ;50.0 65.4 ;50.0 23.8 ;89 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-6.0 ;-0.0 ;Penalty Subtotal ;Overall Score ;
3
"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;28 ;DATE: 09/04/2020 ;SCORE: ;95 ;Good job improving drops! Continue ;to follow this advice to score even ;better: ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of Motion ;Time to Complete ;Efficiency Subtotal ;Penalties ;Ring Cottision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument.lnstrument Collisions ;Instrument -Endoscope Collisions ;Endoscope-Environment Collisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;149.5 cm ;101.5 sec. ;Raw Value ;8.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;2.0 ct. ;1.0 ct. ;50.0 ;50.0 ;• ;• ;handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL' ;Penalty Subtotal ;Overall Score ;pts. ;70.1 ;38.7 ;too ;-0.8 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-4.0 ;.0.3 ;-5 ;95 ;
4
"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPT: ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;29 ;DATE: 09/04/2020 ;SCORE BREAKDOWN: ;Efficiency Metrics ;Economy of Motioh ;Time to Complete ;SCORE: ;Raw Value ;170.8 cm ;138.3 sec. ;Really focus on improving drops by ;following these techniques: ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;• camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL r ;Efficiency Subtotat ;Penalties ;Raw Value ;Ring Collision Warning (Yellow) ;, 14.0 ct. ;0.0 ci. ;Ring Excessive Force (Red) ;Instrument-Instrument Collisions ;0.0 ct. ;Instrument-Endoscope CollisionS ;0.0 ct. ;Endoscope-Environment Collisions ;0.0 ct. ;Excessive Force ;0.0 sec. ;Drops ;5.0 ct. ;Instruments Out of View ;0.0 ct. ;Penalty Subtotal ;Overall Score ;Pts. ;50.0 66.5 ;50.0 25.6 ;92 ;-1.4 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-10.0 ;-0.0 ;-11 ;81 ;
5
"Simulator is not connected to SimNowlLink ;Reports ;PERFORMANCE REPORT ;USER: ;EXERCISE: ;ATTEMPt ;NOTES: ;DemoUser ;Ring Rollercoaster 1 ;31 ;DATE: 09/04/2020 08:33:34 ;SCORE BREAKDOWN: ;SCORE: ;85 ;Good job improving drops! , Continue ;to follow this advice to score, even ;better:, ;• handle grasped objects ;carefully, use the wristed ;instruments to properly position ;object in the grasper. ;• camera clutch to optimize your ;field of view. ;LAUNCH EXERCISE ;INTUITIVE ;SURGICAL r ;Efficiency Metrics ;Economy of Motion ;Time to Complete ;Raw Value ;164.8 cm ;136.6 sec. ;Efficiency Subtotal. ;Penalties ;Ring Collision Warning (Yellow) ;Ring Excessive Force (Red) ;Instrument-instrument Collisions ;Instrument-Endoscope Collisions ;Endoscope-Environment Cottisions ;Excessive Force ;Drops ;Instruments Out of View ;Raw Value ;7.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 ct. ;0.0 sec. ;4.0 ct. ;1.0 ct. ;Penalty Subtotal ;Overall Score ;Pts. ;50.0 67.5 ;50.0 26.2 ;-0.7 ;-0.0 ;-0.0 ;-0.0 ;-0.0 ;-8.0 ;-0.3 ;85 ;
"""#
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