---
title: "init(_:as:transform:)"
framework: regexbuilder
role: symbol
role_heading: Initializer
path: "regexbuilder/trycapture/init(_:as:transform:)-88lf1"
---

# init(_:as:transform:)

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

## Declaration

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

## 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.
