Skip to content

mobilarts/BetterRegex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.