Skip to content

Instantly share code, notes, and snippets.

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