欢迎加入QQ讨论群258996829

Swift 正则表达式类库 Regex

发布时间:2016-07-03 22:54  回复:0  查看:6798  感兴趣:24  赞:0   最后回复:2016-07-03 22:54  

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!")
}

相关开源代码

您还未登录,请先登录

热门帖子

最新帖子