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
nil
if 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) -> Bool
Parameters
input
The string that shall be tested.
Return Value
true
if the expression matches the string,false
otherwise.