You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Querying: How to Use Regex

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

The supplied regular expression must be .NET compatible.

Example

// loads all products, which name
// starts with 'N' or 'A'
List<Product> products = session
    .Query<Product>()
    .Where(x => Regex.IsMatch(x.Name, "^[NA]"))
    .ToList();
// loads all products, which name
// starts with 'N' or 'A'
List<Product> products = await asyncSession
    .Query<Product>()
    .Where(x => Regex.IsMatch(x.Name, "^[NA]"))
    .ToListAsync();
from Products 
where regex(Name, '^[NA]')