From 1282d3a2709064cb847b8757409a7153449faa9d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 22 Oct 2025 21:21:17 +0200 Subject: PostgreSQL: compatibility with PCRE word boundary (#8141) Allow the use of regex `\b` for word boundary (and `\B` for the opposite) even when using PostgreSQL. Follow up of: * https://github.com/FreshRSS/FreshRSS/pull/6706 For instance, `intitle:/\bnew\B/` will find *newest* but not *new* nor *renewal*. Useful in particular to minimise the differences between PHP and database in: * https://github.com/FreshRSS/FreshRSS/pull/7959 --- app/Models/EntryDAOPGSQL.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app') diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index 6211b9a6b..91068919d 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -43,6 +43,12 @@ class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite { protected static function sqlRegex(string $expression, string $regex, array &$values): string { $matches = static::regexToSql($regex); if (isset($matches['pattern'])) { + $replacements = [ // Convert some of the PCRE regex syntax to PostgreSQL + '\\b' => '\\y', // matches only at the beginning or end of a word (was: backspace) + '\\B' => '\\Y', // matches only at a point that is not the beginning or end of a word (was: backslash) + ]; + $matches['pattern'] = str_replace(array_keys($replacements), array_values($replacements), $matches['pattern']); + $matchType = $matches['matchType'] ?? ''; if (str_contains($matchType, 'm')) { // newline-sensitive matching -- cgit v1.2.3