ColaExpression 2.2.0

ColaExpression 2.2.0

测试测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2019 年 4 月
SPM支持 SPM

Meniny 维护。



ColaExpression
Version Author Build Passing Swift
Platforms MIT
Cocoapods Carthage SPM


这是什么?

ColaExpression 是一个用 Swift 编写的跨平台正则表达式库。

要求

  • iOS 9.0+
  • macOS 10.10+
  • watchOS 3.0+
  • tvOS 9.0+
  • Xcode 9 与 Swift 4

安装

CocoaPods

pod 'ColaExpression'

贡献

欢迎您进行分支操作并提交拉取请求。

许可证

ColaExpression 是开源软件,遵守 MIT 许可证。

用法

isMatch() -> Bool

let pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
let str = "[email protected]"
let cola = ColaExpression(pattern)
if cola.isMatch(with: str) {
  print("\(str) is a valid email")
  // [email protected] is a valid email
}
if str.isMatch(pattern: pattern) {
  print("\(str) is a valid email")
  // [email protected] is a valid email
}

matches() -> [String]

let pattern = "[a-z]{3}"
let str = "AAAbbbCCCdddEEEfff"
let cola = ColaExpression(pattern)
let matches = cola.matches(of: str)
// ["bbb", "ddd", "fff"]
let matches = str.matches(pattern: pattern)
// ["bbb", "ddd", "fff"]

replaceOccurences() -> String

let pattern = "[a-z]"
let str = "AAAbbbCCCdddEEEfff"
let replacement = "-"
let cola = ColaExpression(pattern)
let replaced = cola.replaceOccurences(in: str, with: replacement)
// AAA---CCC---EEE---
let replaced = str.replaceOccurences(matches: pattern, with: replacement)
// AAA---CCC---EEE---