---
title: regexp operator
description: Learn the syntax of the regexp operator of the SQL language in Databricks SQL.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/regexp
---

# `regexp` operator

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 10.4 LTS and above

Returns true if `str` matches `regex`. This function is a synonym for [`rlike` operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/rlike.md).

## Syntax

```
str [NOT] regexp regex
```

## Arguments

* `str`: A `STRING` expression in `UTF8_BINARY` collation to be matched.
* `regex`: A `STRING` expression with a matching pattern.

## Returns

A `BOOLEAN`.

The `regex` string must be a regular expression. See [Regular expressions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-regexp-pattern.md) for the supported syntax.
When using literals, use [`raw-literal` (`r` prefix)](https://docs.databricks.com/aws/en/sql/language-manual/data-types/string-type.md) to avoid escape character pre-processing.

`str NOT regexp ...` is equivalent to `NOT(str regexp ...)`.

## Common error conditions

* [INVALID\_PARAMETER\_VALUE.PATTERN](https://docs.databricks.com/aws/en/error-messages/invalid-parameter-value-error-class.md#pattern)

## Examples

### Test whether a string matches a pattern

```sql
> SELECT 'Databricks SQL' regexp r'^Data';
 true

> SELECT 'Spark SQL' regexp r'^Data';
 false
```

### Check whether a string contains a digit

```sql
> SELECT 'order12345' regexp r'\d';
 true
```

### Match case-insensitively

Use the `(?i)` inline flag to ignore case.

```sql
> SELECT 'HELLO WORLD' regexp r'(?i)hello';
 true
```

### Negate a match with `NOT`

```sql
> SELECT 'no digits here' NOT regexp r'\d';
 true
```

### Match a literal backslash

A backslash is a regex metacharacter, so match a literal backslash with `\\`. A raw literal (`r` prefix) avoids having to also double the SQL escape character.

```sql
> SELECT r'%SystemDrive%\Users\John' regexp r'%SystemDrive%\\Users.*';
 true

> SELECT r'%SystemDrive%\Users\John' regexp '%SystemDrive%\\\\Users.*';
 true
```

## Related functions

* [Regular expressions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-regexp-pattern.md)
* [`ilike` operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/ilike.md)
* [`like` operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/like.md)
* [`regexp_extract_all` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regexp_extract_all.md)
* [`regexp_replace` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regexp_replace.md)
* [`rlike` operator](https://docs.databricks.com/aws/en/sql/language-manual/functions/rlike.md)
* [`split` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/split.md)
