Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Created August 12, 2022 08:11
Show Gist options
  • Save eunjin3786/1c94d5809f6f769c43d3e6ddb8e77d82 to your computer and use it in GitHub Desktop.
Save eunjin3786/1c94d5809f6f769c43d3e6ddb8e77d82 to your computer and use it in GitHub Desktop.
import RegexBuilder
let regex = Regex {
"Hi, WWDC"
Capture {
Repeat(.digit, count: 2)
}
"!"
}
let input = "Hi, WWDC21! Hi, WWDC22! Hi Hello"
if let firstMatch = input.firstMatch(of: regex) {
let (firstMatched, digits) = firstMatch.output
print(firstMatched) // Hi, WWDC21!
print(digits) // 21
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment