---
title: "init(_:)"
framework: swift
role: symbol
role_heading: Initializer
path: "swift/regex/init(_:)-52kg"
---

# init(_:)

Creates a regular expression from the given string, using a dynamic capture list.

## Declaration

```swift
init(_ pattern: String) throws
```

## Parameters

- `pattern`: A string with regular expression syntax.

## Discussion

Discussion Use this initializer to create a Regex instance from a regular expression that you have stored in pattern. let simpleDigits = try Regex("[0-9]+") This initializer throws an error if pattern uses invalid regular expression syntax. The output type of the new Regex is the dynamic AnyRegexOutput. If you know the capture structure of pattern ahead of time, use the init(_:as:) initializer instead.
