<!--
{
  "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/Optionally/init(_:_:)-7te1p",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RegexBuilder"
    ],
    "preciseIdentifier" : "s:12RegexBuilder10OptionallyVyACySs_qd_0_Sgqd_1_Sgqd_2_Sgqd_3_SgtG17_StringProcessing0A18RepetitionBehaviorVSg_qd_4_yXEtcSs_AdefGtRszAI0A9ComponentRd_4_qd___qd_0_qd_1_qd_2_qd_3_t0A6OutputRtd_4_r4_lufc"
  },
  "title" : "init(_:_:)"
}
-->

# init(_:_:)

Creates a regex component that matches the given component
zero or one times.

```
init<W, C1, C2, C3, C4>(_ behavior: RegexRepetitionBehavior? = nil, @RegexComponentBuilder _ componentBuilder: () -> some RegexComponent) where Output == (Substring, C1?, C2?, C3?, C4?)
```

## Parameters

`behavior`

The repetition behavior to use when repeating
`component` in the match. If `behavior` is `nil`, the default
repetition behavior is used, which can be changed from
`eager` by calling `repetitionBehavior(_:)` on the resulting
`Regex`.

`componentBuilder`

A builder closure that generates a regex
component.

---

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)