---
title: "rangeOfFirstMatch(in:options:range:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsregularexpression/rangeoffirstmatch(in:options:range:)"
---

# rangeOfFirstMatch(in:options:range:)

Returns the range of the first match of the regular expression within the specified range of the string.

## Declaration

```swift
func rangeOfFirstMatch(in string: String, options: NSRegularExpression.MatchingOptions = [], range: NSRange) -> NSRange
```

## Parameters

- `string`: The string to search.
- `options`: The matching options to use. See doc://com.apple.foundation/documentation/Foundation/NSRegularExpression/MatchingOptions for possible values.
- `range`: The range of the string to search.

## Return Value

Return Value The range of the first match. Returns {NSNotFound, 0} if no match is found.

## Discussion

Discussion This is a convenience method that calls enumerateMatches(in:options:range:using:).

## See Also

### Searching Strings Using Regular Expressions

- [numberOfMatches(in:options:range:)](foundation/nsregularexpression/numberofmatches(in:options:range:).md)
- [enumerateMatches(in:options:range:using:)](foundation/nsregularexpression/enumeratematches(in:options:range:using:).md)
- [matches(in:options:range:)](foundation/nsregularexpression/matches(in:options:range:).md)
- [firstMatch(in:options:range:)](foundation/nsregularexpression/firstmatch(in:options:range:).md)
