Skip to content

Instantly share code, notes, and snippets.

View bugKrusha's full-sized avatar

Jazbo bugKrusha

View GitHub Profile
@bugKrusha
bugKrusha / String+RegularExpression.Swift
Last active November 14, 2018 23:15
Parse string using regular expressions in Swift
extension String {
/// Use a regular expression pattern to find elements in a String.
///
/// - Parameters:
/// - pattern: Regular expression pattern.
/// - options: Regular expressions options.
/// - Returns: Array with elements matching the pattern passed in.
/// - Throws: Regular expression errors.
func matching(pattern: String, options: NSRegularExpression.Options) throws -> [String] {
let regex = try NSRegularExpression(pattern: pattern, options: options)