StructureRegexBuilder5.9.0

    ChoiceOf

    A regex component that chooses exactly one of its constituent regex components when matching.

    iOS
    16.0+
    macOS
    13.0+
    tvOS
    16.0+
    watchOS
    9.0+
    struct ChoiceOf<Output>

    You can use ChoiceOf to provide a group of regex components, each of which can be exclusively matched. In this example, regex successfully matches either a "CREDIT" or "DEBIT" substring:

    let regex = Regex {
        ChoiceOf {
            "CREDIT"
            "DEBIT"
        }
    }
    let match = try regex.prefixMatch(in: "DEBIT    04032020    Payroll $69.73")
    print(match?.0 as Any)
    // Prints "DEBIT"

    Citizens in RegexBuilder

    Conformances

    Members