---
title: "contains(regex:)"
framework: appintentstesting
role: symbol
role_heading: Type Method
platforms: [iOS 27.3+, iPadOS 27.3+, Mac Catalyst 27.3+, macOS 27.3+, tvOS 27.3+, visionOS 27.3+, watchOS 27.3+]
path: "appintentstesting/intentvalueexpectation/contains(regex:)"
---

# contains(regex:)

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

## Declaration

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

## Parameters

- `regex`: The regular expression to search for in the string.

## Return Value

Return Value An expectation that searches a string value for a match for regex.

## Discussion

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.
