<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Regex/contains(captureNamed:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:17_StringProcessing5RegexV8contains12captureNamedSbSS_tF"
  },
  "title" : "contains(captureNamed:)"
}
-->

# contains(captureNamed:)

Returns a Boolean value indicating whether a named capture with the given
name exists.

```
func contains(captureNamed name: String) -> Bool
```

## Parameters

`name`

The name to look for among the regular expression’s
capture groups. Capture group names are case sensitive.

## Discussion

This example shows a regular expression that includes capture groups
named `key` and `value`:

```
let regex = try Regex("(?'key'.+?): (?'value'.+)")
regex.contains(captureNamed: "key")       // true
regex.contains(captureNamed: "VALUE")     // false
regex.contains(captureNamed: "1")         // false
```

---

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)