<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/CompareOptions",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@E@NSStringCompareOptions"
  },
  "title" : "NSString.CompareOptions"
}
-->

# NSString.CompareOptions

These values represent the options available to many of the string classes’ search and comparison methods.

```
struct CompareOptions
```

## Overview

See [Searching, Comparing, and Sorting Strings](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/SearchingStrings.html#//apple_ref/doc/uid/20000149) for details on the effects of these options.

## Topics

### Constants

[`caseInsensitive`](/documentation/Foundation/NSString/CompareOptions/caseInsensitive)

A case-insensitive search.

[`literal`](/documentation/Foundation/NSString/CompareOptions/literal)

Exact character-by-character equivalence.

[`backwards`](/documentation/Foundation/NSString/CompareOptions/backwards)

Search from end of source string.

[`anchored`](/documentation/Foundation/NSString/CompareOptions/anchored)

Search is limited to start (or end, if `NSBackwardsSearch`) of source string.

[`numeric`](/documentation/Foundation/NSString/CompareOptions/numeric)

Numbers within strings are compared using numeric value, that is, `Name2.txt` < `Name7.txt` < `Name25.txt`.

[`diacriticInsensitive`](/documentation/Foundation/NSString/CompareOptions/diacriticInsensitive)

Search ignores diacritic marks.

[`widthInsensitive`](/documentation/Foundation/NSString/CompareOptions/widthInsensitive)

Search ignores width differences in characters that have full-width and half-width forms, as occurs in East Asian character sets.

[`forcedOrdering`](/documentation/Foundation/NSString/CompareOptions/forcedOrdering)

Comparisons are forced to return either `NSOrderedAscending` or `NSOrderedDescending` if the strings are equivalent but not strictly equal.

[`regularExpression`](/documentation/Foundation/NSString/CompareOptions/regularExpression)

The search string is treated as an ICU-compatible regular expression. If set, no other options can apply except [`caseInsensitive`](/documentation/Foundation/NSString/CompareOptions/caseInsensitive) and [`anchored`](/documentation/Foundation/NSString/CompareOptions/anchored). You can use this option only with the `rangeOfString:`… methods and [`replacingOccurrences(of:with:options:range:)`](/documentation/Foundation/NSString/replacingOccurrences(of:with:options:range:)).



---

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)