<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributedStringProtocol/range(of:options:locale:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation24AttributedStringProtocolPAAE5range2of7options6localeSnyAA0bC0V5IndexVGSgqd___So22NSStringCompareOptionsVAA6LocaleVSgtSyRd__lF"
  },
  "title" : "range(of:options:locale:)"
}
-->

# range(of:options:locale:)

Returns the range of a substring in the attributed string, if it exists.

```
func range<T>(of stringToFind: T, options: String.CompareOptions = [], locale: Locale? = nil) -> Range<AttributedString.Index>? where T : StringProtocol
```

## Parameters

`stringToFind`

The string to find.

`options`

Options that affect the search behavior, such as case-insensivity, search direction, and regular expression matching.

`locale`

The locale to use when searching, or `nil` to use the current locale. The default is `nil`.

## Return Value

The range where `stringToFind` exists in the attributed string, or `nil` if it isn’t present.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)