From e646416788bab3287e644dc8d2ab4c714d933652 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 26 Nov 2026 00:48:05 +0100 Subject: [PATCH] Document EF Core regex translation limitations Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- conceptual/EFCore.PG/mapping/translations.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/conceptual/EFCore.PG/mapping/translations.md b/conceptual/EFCore.PG/mapping/translations.md index 366677d9..f37f8d25 100644 --- a/conceptual/EFCore.PG/mapping/translations.md +++ b/conceptual/EFCore.PG/mapping/translations.md @@ -41,14 +41,22 @@ stringValue.TrimEnd(trimChar) | rtrim(stringValu stringValue.TrimStart() | ltrim(stringValue) stringValue.TrimStart(trimChar) | ltrim(stringValue, trimChar) EF.Functions.Reverse(value) | reverse(value) -Regex.IsMatch(stringValue, "^A+") | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) -Regex.IsMatch(stringValue, "^A+", regexOptions) | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) +Regex.IsMatch(stringValue, "^A+") | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) | [1](#regex-note) +Regex.IsMatch(stringValue, "^A+", regexOptions) | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) | [1](#regex-note) +Regex.Replace(stringValue, pattern, replacement) | [regexp_replace(stringValue, pattern, replacement, 'pg')](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | [1](#regex-note) +Regex.Replace(stringValue, pattern, replacement, regexOptions) | [regexp_replace(stringValue, pattern, replacement, flags)](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | [1](#regex-note) +Regex.Count(stringValue, pattern) | [regexp_count(stringValue, pattern, 1, 'p')](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | [1](#regex-note) Requires PostgreSQL 15+ +Regex.Count(stringValue, pattern, regexOptions) | [regexp_count(stringValue, pattern, 1, flags)](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | [1](#regex-note) Requires PostgreSQL 15+ string.Join(", ", a, b) | [concat_ws(', ', a, b)](https://www.postgresql.org/docs/current/functions-string.html#FUNCTIONS-STRING-OTHER) string.Join(", ", array) | [array_to_string(array, ', ', '')](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE) string.Join(", ", agg_strings) | [string_agg(agg_strings, ', ')](https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE) | See [Aggregate functions](#aggregate-functions). EF.Functions.StringToArray(s, "\|") | [string_agg(s, '\|')](https://www.postgresql.org/docs/current/functions-string.html#FUNCTION-STRING-TO-ARRAY) EF.Functions.StringToArray(s, "\|", "FOO") | [string_agg(s, '\|', 'FOO')](https://www.postgresql.org/docs/current/functions-string.html#FUNCTION-STRING-TO-ARRAY) +1 These translations use [PostgreSQL's regular expression syntax and semantics](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP), not .NET's. In particular, unless `RegexOptions.Singleline` is specified, negated character classes such as `[^x]` do not match LF (`\n`), unlike in .NET: `a[^x]b` matches `"a\nb"` in .NET but not in PostgreSQL. Use client-side evaluation when exact .NET semantics are required. + +`RegexOptions` arguments must be constant, and `RightToLeft` and `ECMAScript` are not supported. Only `IgnoreCase`, `Multiline`, `Singleline` and `IgnorePatternWhitespace` affect the generated SQL. Only the listed static overloads are translated; instance methods, overloads accepting a match timeout or `MatchEvaluator`, and other `Regex` methods are not translated. + ## Date and time functions > [!NOTE]