---
title: "firstMatch(of:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/bidirectionalcollection/firstmatch(of:)-7m8f4"
---

# firstMatch(of:)

Returns the first match of the specified regex within the collection.

## Declaration

```swift
func firstMatch<Output>(of r: some RegexComponent) -> Regex<Output>.Match?
```

## Return Value

Return Value The first match of regex in the collection, or nil if there isn’t a match.
