<!--
{
  "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/TryCapture/init(_:as:transform:)-9p9ig",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RegexBuilder"
    ],
    "preciseIdentifier" : "s:12RegexBuilder10TryCaptureV_2as9transformACySs_qd_6_qd_0_qd_1_qd_2_qd_3_qd_4_qd_5_tGqd_7__AA9ReferenceVyqd_6_Gqd_6_Sgqd__KctcSs_qd_6_qd_0_qd_1_qd_2_qd_3_qd_4_qd_5_tRsz17_StringProcessing0A9ComponentRd_7_qd___qd_0_qd_1_qd_2_qd_3_qd_4_qd_5_t0A6OutputRtd_7_r7_lufc"
  },
  "title" : "init(_:as:transform:)"
}
-->

# init(_:as:transform:)

Creates a capture for the given component using the specified
reference, attempting to transform with the given closure.

```
init<W, C1, C2, C3, C4, C5, C6, NewCapture>(_ component: some RegexComponent, as reference: Reference<NewCapture>, transform: @escaping (W) throws -> NewCapture?) where Output == (Substring, NewCapture, C1, C2, C3, C4, C5, C6)
```

## Parameters

`component`

The regex component to capture.

`reference`

The reference to use for anything captured by
`component`.

`transform`

A closure that takes the substring matched by
`component` and returns a new value to capture, or `nil` if
matching should proceed, backtracking if allowed. If `transform`
throws an error, matching is abandoned and the error is returned
to the caller.

---

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)