Regex 是一个 Swift 正则表达式类库。
示例代码:
//创建 // 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!") }