---
title: "firstRange(of:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/bidirectionalcollection/firstrange(of:)-1di7b"
---

# firstRange(of:)

Finds and returns the range of the first occurrence of a given regex within the collection.

## Declaration

```swift
func firstRange(of regex: some RegexComponent) -> Range<Self.Index>?
```

## Parameters

- `regex`: The regex to search for.

## Return Value

Return Value A range in the collection of the first occurrence of regex. Returns nil if regex is not found.
