Skip to content

mobilarts/BetterRegex

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
Pod
 
 
 
 
 
 
 
 
 
 

BetterRegex

CI Status Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

The library is straightforward to use.

  1. Define your regular expression matching pattern as you normally would, including named groups (which are not supported by the default NSRegularExpression). Named groups follow the same method used in PHP: (?<name_of_group>your match)

let pattern = "(?w.+?)\s(?a.+?)$"

  1. Instantiate the main class using your pattern: BetterRegex(pattern: pattern) (it is better for performance to reuse that class for the same pattern every time you need it rather than reinstantiate it every time)

let test = BetterRegex(pattern: pattern)

  1. Obtain your matches back:

let regexOptions: NSMatchingOptions = NSMatchingOptions.WithTransparentBounds let matches: RegexResults = test.extractMatches("welcome all", options: regexOptions)

  1. Access your matches: the RegexResults structure that is returned with convenient accessor methods by name and index. Heye you can get your optional string for a key name using matches.getKey("test") or matches.getKey("amatch") or through numeric indexes for non-named groups and named groups alike via matches.getKey(0) for example.

Requirements

A reasonably recent version of XCode

Installation

BetterRegex is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BetterRegex"

Author

Mobilarts / Louis-Eric Simard, louis-eric @ mobilarts -- dot-- com

License

BetterRegex is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published