---
title: "Using Regex"
description: "Filter RavenDB query results using regular expressions to match complex patterns in document fields with the Regex query method."
url: "https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex"
version: "7.2"
language: "python"
---

# Using Regex

> Client language: Python. Also available for [C#](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex.md), [Java](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex.java.md), [PHP](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex.php.md), [Node.js](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/using-regex.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

To return only documents that match regular expression,  
use the `where_regex` method which enables RavenDB to perform server-side pattern matching queries.

The supplied regular expression must be [.NET compatible](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.7.1).

## Example

### Python

```python
# loads all products, which name
# starts with 'N' or 'A'
products = list(session.query(object_type=Product).where_regex("Name", "^[NA]"))
```

### RQL

```sql
from Products 
where regex(Name, '^[NA]')
```

## See also

- [Query overview](https://docs.ravendb.net/7.2/querying/overview.python.md)
- [Full-text search](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/full-text-search.python.md)
- [Query with exact match](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/exact-match-query.python.md)
- [Querying: Basics](https://docs.ravendb.net/7.2/indexes/querying/query-index.python.md)
