Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rockfordwei/perfect-pcre2
An express Swift class wrapper for PCRE2
https://github.com/rockfordwei/perfect-pcre2
pcre2 perfect regular-expression swift
Last synced: 3 months ago
JSON representation
An express Swift class wrapper for PCRE2
- Host: GitHub
- URL: https://github.com/rockfordwei/perfect-pcre2
- Owner: RockfordWei
- License: apache-2.0
- Created: 2018-02-14T23:23:57.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T17:35:09.000Z (over 3 years ago)
- Last Synced: 2024-10-30T17:17:48.317Z (3 months ago)
- Topics: pcre2, perfect, regular-expression, swift
- Language: Swift
- Size: 9.77 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Perfect-PCRE2
This project provides an easy solution to extract captured groups from a string by a PCRE2 compatible regular expression.
This package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project but can also be used as an independent module.
## Quick Start
### Prerequisites
#### Swift Version
Swift 4.2+
#### macOS
```
$ brew install pcre2
```#### Ubuntu Linux
```
$ sudo apt-get install libpcre2-dev
```### Swift Package Manager
Add dependencies to your Package.swift
``` swift
.package(url: "https://github.com/RockfordWei/Perfect-PCRE2.git",
from: "3.1.0")// on target section:
.target(
// name: "your project name",
dependencies: ["PerfectPCRE2"]),
```### Import Perfect PCRE2 Library
Add the following header to your swift source code:
``` swift
import PerfectPCRE2
```### Simple Usage
``` swift
let lines = try """
HTTP/1.1 100 continue
HTTP/1.0 200 OK
""".pcre2Match(pattern: "([A-Z]+)/([0-9.]+)\\s+([0-9]+)\\s+(.*)")lines.forEach { line in
print("full: $0", line[0]) // the full match
print("head: $1", line[1]) // "HTTP"
print("vers: $2", line[2]) // 1.1 or 1.0
print("code: $3", line[3]) // 100 or 200
print("stat: $4", line[4]) // continue or OK
}
```## Further Information
For more information on the Perfect project, please visit [perfect.org](http://perfect.org).