# `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://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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:

```json
{ "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

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

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

### Example output

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