---
title: ChoiceOf
framework: regexbuilder
role: symbol
role_heading: Structure
path: regexbuilder/choiceof
---

# ChoiceOf

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

## Declaration

```swift
struct ChoiceOf<Output>
```

## Overview

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"

## Topics

### Initializers

- [init(_:)](regexbuilder/choiceof/init(_:).md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [RegexComponent](swift/regexcomponent.md)

## See Also

### Components

- [CharacterClass](regexbuilder/characterclass.md)
- [Anchor](regexbuilder/anchor.md)
- [Lookahead](regexbuilder/lookahead.md)
- [NegativeLookahead](regexbuilder/negativelookahead.md)
