Regex 是一個 Swift 正則表達式類庫。
示例代碼:
//創(chuàng)建 // Use `Regex.init(_:)` to build a regex from a static pattern let greeting = Regex("hello (world|universe)") // Use `Regex.init(string:)` to construct a regex from dynamic data, and // gracefully handle invalid input var validations: [String: Regex] for (name, pattern) in config.loadValidations() { do { validations[name] = try Regex(string: pattern) } catch { print("error building validation \(name): \(error)") } } //匹配 if greeting.matches("hello universe!") { print("wow, you're friendly!") }