import Foundation
let pattern = #"Seat (?P<playerseat>[0-9]+): (?P<playername>[.?]+)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = ##"""
he name of first value, first 17/04/2013 11:30:00 - A:30.0
PokerStars Hand #152844641611: Tournament #1556870024, $0.44+$0.44+$0.12 USD Hold'em No Limit - Level I (25/50) - 2016/05/04 13:15:07 BRT [2016/05/04 12:15:07 ET]
Table '1556870024 3' 6-max Seat #1 is the button
Seat 1: vitalijus (500 in chips)
Seat 2: papoca555 (500 in chips)
Seat 3: SITBACKNOW (500 in chips)
Seat 4: hackerpex (500 in chips)
Seat 5: vovan189 (500 in chips)
Seat 6: DiMers80 (500 in chips)
vitalijus: posts the ante 10
papoca555: posts the ante 10
SITBACKNOW: posts the ante 10
hackerpex: posts the ante 10
vovan189: posts the ante 10
DiMers80: posts the ante 10
papoca555: posts small blind 25
SITBACKNOW: posts big blind 50
*** HOLE CARDS ***
Dealt to hackerpex [7h 6h]
hackerpex: folds
vovan189: calls 50
DiMers80: raises 440 to 490 and is all-in
vitalijus: folds
papoca555: folds
SITBACKNOW: calls 440 and is all-in
vovan189: calls 440 and is all-in
*** FLOP *** [5c 2c 3s]
*** TURN *** [5c 2c 3s] [Ah]
*** RIVER *** [5c 2c 3s Ah] [4s]
*** SHOW DOWN ***
SITBACKNOW: shows [Ks Tc] (a straight, Ace to Five)
vovan189: shows [6d As] (a straight, Deuce to Six)
DiMers80: shows [Kc Th] (a straight, Ace to Five)
vovan189 collected 1555 from pot
vovan189 wins the $0.44 bounty for eliminating SITBACKNOW
vovan189 wins the $0.44 bounty for eliminating DiMers80
SITBACKNOW finished the tournament in 35th place
DiMers80 finished the tournament in 35th place
*** SUMMARY ***
Total pot 1555 | Rake 0
Board [5c 2c 3s Ah 4s]
Seat 1: vitalijus (button) folded before Flop (didn't bet)
Seat 2: papoca555 (small blind) folded before Flop
Seat 3: SITBACKNOW (big blind) showed [Ks Tc] and lost with a straight, Ace to Five
Seat 4: hackerpex folded before Flop (didn't bet)
Seat 5: vovan189 showed [6d As] and won (1555) with a straight, Deuce to Six
Seat 6: DiMers80 showed [Kc Th] and lost with a straight, Ace to Five
PokerStars Hand #152844655854: Tournament #1556870024, $0.44+$0.44+$0.12 USD Hold'em No Limit - Level I (25/50) - 2016/05/04 13:15:28 BRT [2016/05/04 12:15:28 ET]
Table '1556870024 3' 6-max Seat #2 is the button
Seat 1: vitalijus (490 in chips)
Seat 2: papoca555 (465 in chips)
Seat 4: hackerpex (490 in chips)
Seat 5: vovan189 (1555 in chips)
vitalijus: posts the ante 10
papoca555: posts the ante 10
hackerpex: posts the ante 10
vovan189: posts the ante 10
hackerpex: posts small blind 25
vovan189: posts big blind 50
*** HOLE CARDS ***
Dealt to hackerpex [Jd Ad]
"""##
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