import Foundation
// WARNING: You included a flag that Swift doesn't support: u
// When this flag is set, it makes the pattern and subject strings to be treated as unicode.
// Swift already treats the pattern and subject strings as unicode by default, so including this flag is redundant.
let pattern = #"\W\K(?|(?=(your|her|his|its|our|their|mine|yours|hers|ours|theirs|my|a|an|the)\b)()|(\w+|\*)\b)\s+\b(bore|bade|bit|blew|chose|dove|drew|drove|drank|ate|fell|forbade|forgot|forgave|forsook|froze|got|gave|went|grew|hid|knew|lay|lit|mistook|overdid|overtook|overthrew|rode|rang|rose|saw|shook|shore|shrank|sang|sank|smote|spoke|stole|stank|strod|strove|swore|swam|took|threw|trod|woke|wore|wove|wrote)\b(?=\s)"#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
1) And Ôhe spoke to him
2) and spoke to his sons
3) his host, spoke to
4) and took of every
5) and * took a garment
6) And * took * his son
7) merchants fetched a drove of horses
8) ÔI am a rose
9) blossom like a rose
10) But a † rose out
11) that * rose up
12) and a bit
13) and Ôthey bit the people
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
let substitutionString = #"$1 - $2 - $3 - "#
let result = regex.stringByReplacingMatches(in: testString, range: stringRange, withTemplate: substitutionString)
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