RegexPredicate

public struct RegexPredicate : Predicate

The RegexPredicate struct is used to define regular expression based conditions used to evaluate input strings.

let predicate = RegexPredicate(expression: "^\\d+$")
let isValid = predicate.evaluate(with: "1234567890")
  • Declaration

    Swift

    public typealias InputType = String
  • Returns a new RegexPredicate instance.

    let predicate = RegexPredicate(expression: "^\\d+$")
    let isValid = predicate.evaluate(with: "1234567890")
    

    Declaration

    Swift

    public init(expression: String)

    Parameters

    expression

    A String describing the regular expression.

  • Returns a Boolean value that indicates whether a given input matches the regular expression specified by the receiver.

    Declaration

    Swift

    public func evaluate(with input: InputType) -> Bool

    Parameters

    input

    The input against which to evaluate the receiver.

    Return Value

    true if input matches the regular expression specified by the receiver, otherwise false.