# `REGEXP_COUNT`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the number of times a regular expression pattern occurs in a string.

## Syntax

```sql
regexp_count(<string>, <pattern>)
```

## Arguments

### Required

- `<string>`: The string to search within.
- `<pattern>`: The regular expression pattern to count.

## Returns

Returns an integer representing the number of times the pattern occurs.

## Considerations

- Returns `0` when no matches are found.
- Counts non-overlapping matches.
- For detailed regex syntax, see [Regular Expression Syntax](/docs/data/data-cloud-query-guide/references/dc-sql-reference/string-matching.md#regular-expression-syntax).

## Examples

### Count Digits

Count individual digits in a string.

```sql
SELECT regexp_count('a1b2c3', '\d') AS result;
```

Returns `3`.

### Count Words

Count words in a string.

```sql
SELECT regexp_count('The quick brown fox', '\w+') AS result;
```

Returns `4`.

### No Matches

Returns `0` when pattern is not found.

```sql
SELECT regexp_count('abcdef', '\d') AS result;
```

Returns `0`.

### Count Specific Patterns

Count occurrences of a specific pattern.

```sql
SELECT regexp_count('banana', 'an') AS result;
```

Returns `2`.

### Use for Validation

Check for expected number of matches.

```sql
SELECT phone FROM contacts
WHERE regexp_count(phone, '\d') = 10;
```

Returns phone numbers with exactly 10 digits.

## Related Documentation

- [REGEXP_SUBSTR](/docs/data/data-cloud-query-guide/references/dc-sql-reference/regexp-substr.md)
- [REGEXP_INSTR](/docs/data/data-cloud-query-guide/references/dc-sql-reference/regexp-instr.md)
- [Regular Expression Syntax](/docs/data/data-cloud-query-guide/references/dc-sql-reference/string-matching.md#regular-expression-syntax)
