Swiftpack.co - yhkaplan/Reg as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by yhkaplan.
yhkaplan/Reg 0.3.0
A convenient Ruby-like wrapper for NSRegularExpression
⭐️ 4
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/yhkaplan/Reg.git", from: "0.3.0")

Reg

Swift Version

Reg is a friendly wrapper for NSRegularExpression

TLDR

Turn this:

let range = NSRange(location: 0, length: string.utf16.count)
let regex = try? NSRegularExpression(pattern: "^gummy bears have no cares")
let str = "gummy bears have no cares"
let firstMatch = regexs?.firstMatch(in: str, options: [], range: range)
let matchRange = Range(firstMatch.range, in: str)

let matchStr = String(str[matchRange])

into this:

let str = "gummy bears have no cares"
let matchStr = "^gummy bears have no cares".firstMatch(in: str)

Features

  • matches
  • hasMatch
  • firstMatch
  • replacingOccurrences
  • captures
  • Operators
    • =~
    • !~

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics