Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created March 22, 2021 19:17
Show Gist options
  • Save ayosec/ac8e0c55c3a3f3c352ab493a53a1ded1 to your computer and use it in GitHub Desktop.
Save ayosec/ac8e0c55c3a3f3c352ab493a53a1ded1 to your computer and use it in GitHub Desktop.
import Foundation
let data = "aaa 11-22 bbb 33-44 ccc"
let regex = try! NSRegularExpression(pattern: #"\d+-\d+"#)
let range = NSRange(data.startIndex..., in: data)
regex.enumerateMatches(in: data, options: [], range: range) { (match, _, _) in
print(data.substring(with: match!.range))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment