Skip to content

Instantly share code, notes, and snippets.

@between40and2
Last active November 16, 2022 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save between40and2/b972022feeaaeaf0809af012611f4062 to your computer and use it in GitHub Desktop.
Save between40and2/b972022feeaaeaf0809af012611f4062 to your computer and use it in GitHub Desktop.
// https://developer.apple.com/videos/play/wwdc2022/110357
import RegexBuilder
func ~=<T>(pattern :Regex<T> , value: String) -> Bool {
do {
return try pattern.firstMatch(in: value) != nil
} catch {
return false
}
}
switch ("πŸ§Ÿβ€β™€οΈπŸ’–πŸ§ ", "The Brain Cafe\u{301}") {
case (/.\N{SPARKLING HEART}./, /.*cafΓ©/.ignoresCase()):
print("Oh no! πŸ§Ÿβ€β™€οΈπŸ’–πŸ§ , but πŸ§ πŸ’–β˜•οΈ!")
default:
print("No conflicts found")
}
let input = "Oh no! πŸ§Ÿβ€β™€οΈπŸ’–πŸ§ , but πŸ§ πŸ’–β˜•οΈ!"
if let m0 = input.firstMatch(of: /.\N{SPARKLING HEART}./) {
print(m0.0) // // πŸ§Ÿβ€β™€οΈπŸ’–πŸ§ 
print(m0.range)
print(m0.output) // // πŸ§Ÿβ€β™€οΈπŸ’–πŸ§ 
}
if let m1 = input.firstMatch(of: /.\N{SPARKLING HEART}./.matchingSemantics(.unicodeScalar)) {
print(m1.output) // οΈπŸ’–πŸ§ 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment