Skip to content

Instantly share code, notes, and snippets.

View squarefrog's full-sized avatar
😍
❤️ Swift

Taylor Williamson squarefrog

😍
❤️ Swift
  • Cambridgeshire, UK
View GitHub Profile
@squarefrog
squarefrog / PatternMatch.swift
Created February 27, 2020 13:39
Regex warning.
import Foundation
// from https://www.hackingwithswift.com/articles/108/how-to-use-regular-expressions-in-swift
extension String {
static func ~= (lhs: String, rhs: String) -> Bool {
guard let regex = try? NSRegularExpression(pattern: rhs) else { return false }
let range = NSRange(location: 0, length: lhs.utf16.count)
return regex.firstMatch(in: lhs, options: [], range: range) != nil
}