Skip to content

Commit 570c725

Browse files
rojiCopilot
andauthored
Document EF Core regex translation limitations (#485)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 214c2b4 commit 570c725

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎conceptual/EFCore.PG/mapping/translations.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ stringValue.TrimEnd(trimChar) | rtrim(stringValu
4141
stringValue.TrimStart() | ltrim(stringValue)
4242
stringValue.TrimStart(trimChar) | ltrim(stringValue, trimChar)
4343
EF.Functions.Reverse(value) | reverse(value)
44-
Regex.IsMatch(stringValue, "^A+") | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options)
45-
Regex.IsMatch(stringValue, "^A+", regexOptions) | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options)
44+
Regex.IsMatch(stringValue, "^A+") | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) | <sup>[1](#regex-note)</sup>
45+
Regex.IsMatch(stringValue, "^A+", regexOptions) | [stringValue ~ '^A+'](http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP) (with options) | <sup>[1](#regex-note)</sup>
46+
Regex.Replace(stringValue, pattern, replacement) | [regexp_replace(stringValue, pattern, replacement, 'pg')](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | <sup>[1](#regex-note)</sup>
47+
Regex.Replace(stringValue, pattern, replacement, regexOptions) | [regexp_replace(stringValue, pattern, replacement, flags)](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | <sup>[1](#regex-note)</sup>
48+
Regex.Count(stringValue, pattern) | [regexp_count(stringValue, pattern, 1, 'p')](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | <sup>[1](#regex-note)</sup> Requires PostgreSQL 15+
49+
Regex.Count(stringValue, pattern, regexOptions) | [regexp_count(stringValue, pattern, 1, flags)](https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP) | <sup>[1](#regex-note)</sup> Requires PostgreSQL 15+
4650
string.Join(", ", a, b) | [concat_ws(', ', a, b)](https://www.postgresql.org/docs/current/functions-string.html#FUNCTIONS-STRING-OTHER)
4751
string.Join(", ", array) | [array_to_string(array, ', ', '')](https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE)
4852
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).
4953
EF.Functions.StringToArray(s, "\|") | [string_agg(s, '\|')](https://www.postgresql.org/docs/current/functions-string.html#FUNCTION-STRING-TO-ARRAY)
5054
EF.Functions.StringToArray(s, "\|", "FOO") | [string_agg(s, '\|', 'FOO')](https://www.postgresql.org/docs/current/functions-string.html#FUNCTION-STRING-TO-ARRAY)
5155

56+
<sup id="regex-note">1</sup> 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.
57+
58+
`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.
59+
5260
## Date and time functions
5361

5462
> [!NOTE]

0 commit comments

Comments
 (0)