---
title: "ranges(of:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/bidirectionalcollection/ranges(of:)-40wx3"
---

# ranges(of:)

Finds and returns the ranges of the all occurrences of a given sequence within the collection.

## Declaration

```swift
func ranges(of regex: some RegexComponent) -> [Range<Self.Index>]
```

## Parameters

- `regex`: The regex to search for.

## Return Value

Return Value A collection or ranges in the receiver of all occurrences of regex. Returns an empty collection if regex is not found.
