import Foundation
let pattern = #"."#
let regex = try! NSRegularExpression(pattern: pattern)
let testString = #"""
An de snou frai and de colei grei Chicago mun beby beibi Charlis morlis de In the guetto (In the guetooo). An de jar mama crai Cosinifi guan sido sido ni modrili yian grin monfi in de gue e to.
[my_shortcode id="1" type="lorem"]lorem ipsum dolor sit amet[/my_shortcode]
Pipol yon ondre tain de chili jil pija. E jil grou yon gui yon man dei. Toque lo que yu an mi. A güi chi blai chu si. De güi simpli ten an qüen. Anblon delon de güei Güedengüelten.
[my_shortcode id="2" type="In-sollicitudin"]In sollicitudin
ullamcorper dolor[/my_shortcode]
A de güelguei jei qui lo you güi re ni brus prisis tri yi guai brus in de guetoooo. An de jan gai ben. So si estarer churruan estrit nai li chus tul fili ji fanch fisin de gueto (In the guetooo).
"""#
let stringRange = NSRange(location: 0, length: testString.utf16.count)
if let firstMatch = regex.firstMatch(in: testString, range: stringRange) {
let result: [String] = (1 ..< firstMatch.numberOfRanges).map { (testString as NSString).substring(with: firstMatch.range(at: $0)) }
print(result)
} else {
print("No matches were found.")
}
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