Created
August 12, 2022 08:11
-
-
Save eunjin3786/1c94d5809f6f769c43d3e6ddb8e77d82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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