Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yhkaplan/reg
A convenient Ruby-like wrapper for NSRegularExpression
https://github.com/yhkaplan/reg
Last synced: 4 months ago
JSON representation
A convenient Ruby-like wrapper for NSRegularExpression
- Host: GitHub
- URL: https://github.com/yhkaplan/reg
- Owner: yhkaplan
- License: mit
- Created: 2019-01-25T04:41:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T07:30:52.000Z (about 3 years ago)
- Last Synced: 2024-09-17T05:02:12.979Z (4 months ago)
- Language: Swift
- Size: 22.5 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reg
[![Swift Version](https://img.shields.io/badge/Swift-5.5.x-orange.svg)]()
Reg is a friendly wrapper for NSRegularExpression
## TLDR
Turn this:
```swift
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:
```swift
let str = "gummy bears have no cares"
let matchStr = "^gummy bears have no cares".firstMatch(in: str)
```## Features
- matches
- hasMatch
- firstMatch
- replacingOccurrences
- captures
- Operators
- =~
- !~