Regex

public class Regex

A helper that makes using Regular Expression easier.

  • Find all matches in a string with a given pattern.

    Throws

    The errors that could happen during creating the NSRegularExpression object.

    Declaration

    Swift

    public static func findAll(pattern: String,
                               string: String,
                               options: NSRegularExpression.Options = [],
                               matchingOptions: NSRegularExpression.MatchingOptions = []
    ) throws -> [Match]

    Parameters

    pattern

    The pattern.

    string

    The string.

    options

    The options to build the NSRegularExpression object.

    matchingOptions

    The options for matching.

    Return Value

    The matches.

  • Find the first match in a string with a given pattern.

    Throws

    The errors that could happen during creating the NSRegularExpression object.

    Declaration

    Swift

    public func findFirst(pattern: String,
                          string: String,
                          options: NSRegularExpression.Options = [],
                          matchingOptions: NSRegularExpression.MatchingOptions = []
    ) throws -> Match?

    Parameters

    pattern

    The pattern.

    string

    The string.

    options

    The options to build the NSRegularExpression object.

    matchingOptions

    The options for matching.

    Return Value

    The first match.

  • Makes a new string by replacing the matches with a template.

    Throws

    The errors that could happen during creating the NSRegularExpression object.

    Declaration

    Swift

    public func replace(pattern: String,
                        string: String,
                        template: String,
                        options: NSRegularExpression.Options = [],
                        matchingOptions: NSRegularExpression.MatchingOptions = []
    ) throws -> String

    Parameters

    pattern

    The pattern.

    string

    The string.

    template

    The template.

    options

    The options to build the NSRegularExpression object.

    matchingOptions

    The options for matching.

    Return Value

    The replaced string.