firstRange(of:)

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

iOS
16.0+
macOS
13.0+
tvOS
16.0+
watchOS
9.0+
func firstRange(of regex: some RegexComponent) -> Range<Self.Index>?

Parameters

regex

The regex to search for.

Returns

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