<!--
{
  "availability" : [
    "iOS: 27.3.0 -",
    "iPadOS: 27.3.0 -",
    "macCatalyst: 27.3.0 -",
    "macOS: 27.3.0 -",
    "tvOS: 27.3.0 -",
    "visionOS: 27.3.0 -",
    "watchOS: 27.3.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppIntentsTesting",
  "identifier" : "/documentation/AppIntentsTesting/IntentValueExpectation/contains(regex:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "App Intents Testing",
      "AppIntentsTesting"
    ],
    "preciseIdentifier" : "s:17AppIntentsTesting22IntentValueExpectationPA2A09PrimitiveF0VRszrlE8contains5regexAESS_tFZ"
  },
  "title" : "contains(regex:)"
}
-->

# contains(regex:)

Creates an expectation that requires the value to be a string that
contains a match for a regular expression.

```
static func contains(regex: String) -> Self
```

## Parameters

`regex`

The regular expression to search for in the string.

## Return Value

An expectation that searches a string value for a match for
`regex`.

## Discussion

The regular expression can match anywhere in the string, so
`.contains(regex: "Building")` also matches “Old Building 4”. To match
the whole string, anchor the regular expression with `^` and `$`. A
value that isn’t a string doesn’t satisfy the expectation.

---

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)