RegularExpression
public class RegularExpression
This class represents a compiled regular expression.
See
Taken from http://benscheirman.com/2014/06/regex-in-swift/-
The internal representation of the regular expression
Declaration
Swift
private let internalExpression: NSRegularExpression -
Compile a regular expression.
Note
Matching will be performed case insensitive.
Declaration
Swift
public init?(_ pattern: String)Return Value
nilif the expression cannot be compiled, i.e. if it is invalid. -
Tests if the regular expression matches a given string
input.Example
let pattern = RegularExpression("^The")! let sentence = "The world is flat." if pattern.matches(sentence) { // The sentence starts with "The" }Declaration
Swift
public func matches(_ input: String) -> BoolParameters
inputThe string that shall be tested.
Return Value
trueif the expression matches the string,falseotherwise.
View on GitHub
RegularExpression Class Reference