Latest 2.0
Homepage https://github.com/glaurent/SwiftRegExp
License BSD
Platforms ios 9.3, osx 10.10
Authors

What is this

SwiftyRegExp is a simple and convenient Swift wrapper around NSRegularExpression. It was inspired by Ben Scheirman’s "RegEx in Swift" post

NOTE : a better framework with more features can be found at https://github.com/sharplet/Regex

Install using CocoaPods

use_frameworks!

pod "SwiftRegExp", "~> 1.4"

Then import it where you want it:

import SwiftRegExp

Examples

Simple boolean match

let regexp = try RegExp("abc.*")
if regexp.isMatching("abcdef") {
  println("match!")
} else {
  println("error")
}

Get matched string

let regexp = try RegExp("abc.*")
if let match = "abcdef" =~ regexp {
   println("match : (match)!")
} else {
   println("error")
}

Get all matches

Also works with capture groups :

let regexp = try RegExp("abc(.*)def(.*)")
let matches = regexp.allMatches("abcXXXdefYYYY")
for match in matches {
    println("match (match)")
}

this will print "abcXXXdefYYYY", "XXX", "YYYY"

How to use

Simply drop the RegExp.swift file in your project

Latest podspec

{
    "name": "SwiftRegExp",
    "version": "2.0",
    "summary": "SwiftyRegExp is a simple and convenient Swift wrapper around NSRegularExpression. It was inspired by Ben Scheirman's "RegEx in Swift" post",
    "homepage": "https://github.com/glaurent/SwiftRegExp",
    "license": "BSD",
    "authors": {
        "Guillaume Laurent": "[email protected]"
    },
    "source": {
        "git": "https://github.com/glaurent/SwiftRegExp.git",
        "tag": "2.0"
    },
    "platforms": {
        "ios": "9.3",
        "osx": "10.10"
    },
    "source_files": "*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This