Swiftpack.co - RockfordWei/Perfect-PCRE2 as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by RockfordWei.
RockfordWei/Perfect-PCRE2 3.1.0
An express Swift class wrapper for PCRE2
⭐️ 5
🕓 2 years ago
.package(url: "https://github.com/RockfordWei/Perfect-PCRE2.git", from: "3.1.0")

Perfect-PCRE2

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.2 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

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 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

.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:

import PerfectPCRE2

Simple Usage

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.

GitHub

link
Stars: 5
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

upgrading to Swift 4.2
5 years ago

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