<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/RegexBuilder/ChoiceOf",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "RegexBuilder"
    ],
    "preciseIdentifier" : "s:12RegexBuilder8ChoiceOfV"
  },
  "title" : "ChoiceOf"
}
-->

# ChoiceOf

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

```
struct ChoiceOf<Output>
```

## Overview

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"
```

## Relationships

### Conforms To

[`Escapable`](/documentation/Swift/Escapable)

[`RegexComponent`](/documentation/Swift/RegexComponent)

[`Copyable`](/documentation/Swift/Copyable)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)