Using Regex

To return only documents that match a regular expression ("regex"),
use the whereRegex method which enables RavenDB to perform server-side pattern matching queries.

The supplied regular expression must be .NET compatible.

Example

Load all products whose name starts with 'N' or 'A'.

/** @var array<Product> $products */
$products = $session
    ->query(Product::class)
    ->whereRegex("Name", "^[NA]")
    ->toList();
from Products 
where regex(Name, '^[NA]')

Syntax

function whereRegex(?string $fieldName, ?string $pattern): FilterDocumentQueryBaseInterface;
Parameter Type Description
$fieldName ?string Name of the field to query
$pattern ?string Pattern to query for