Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fmatches.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Fmatches.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `matches`

## Description

Returns `true` if a string matches a given regular expression. The expression is applied to the entire string; partial matches return `false`.

## Syntax

Like many functions in DataPrime, `matches` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
matches(value: string, pattern: regexp): bool
```

```
(value: string).matches(pattern: regexp): bool
```

## Arguments

| Name      | Type     | Required | Description                            |
| --------- | -------- | -------- | -------------------------------------- |
| `value`   | `string` | **true** | The string to test                     |
| `pattern` | `regexp` | **true** | The regular expression to test against |

## Example

**Detect malformed fields**

Consider the following documents:

```
{ "msg_structured": "User Chris bought 10 Sunglasses" }

{ "msg_structured": "User James bought 1 Bed" }

{ "msg_structured": "User Rick won't give you up" }
```

The third entry is incomplete. Use `matches` to filter out malformed values:

### Example query

* Function notation
* Method notation

```
filter !matches(msg_structured, /User [a-z|A-Z]+ bought d+ [a-z|A-Z]+/)
```

```
filter !msg_structured.matches(/User [a-z|A-Z]+ bought d+ [a-z|A-Z]+/)
```

### Example output

```
{ "msg_structured": "User Rick won't give you up" }
```
