Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uPgky-00DVgE-8Y for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Jun 2025 12:10:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uPgkv-00BtLd-6m for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Jun 2025 12:10:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uPgku-00BtLU-Sl for pgsql-bugs@lists.postgresql.org; Thu, 12 Jun 2025 12:10:05 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uPgkt-001bIq-1I for pgsql-bugs@lists.postgresql.org; Thu, 12 Jun 2025 12:10:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version :References:Reply-To:Message-ID:Subject:To:Sender:From:Date:Cc:Content-ID: Content-Description; bh=bJk1GukrdmcSES6A/hir4PpzkaeEA8Rsvy3KqSk6vVs=; b=XKzrb X4MGskZrLEbhyvMcIQvBO5VnzDsnBh5f+C3UJsVb0LuiQM+76dH4gcV3GghQviQIYjNDOcbdhAhar 8MSGSDkKaoaR4KSDLTCHdzLPd4uMTQE99Qv9tlLcX1DBWavrw++4Wfpb/uXhiylyj3JDxuCYlqsqa WsYhQxAkdhVk=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1uPgkq-003UeS-1l; Thu, 12 Jun 2025 14:10:00 +0200 Date: Thu, 12 Jun 2025 14:10:00 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: anudeepvattikonda0404@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18956: Observing an issue in regexp_count() Message-ID: Reply-To: depesz@depesz.com References: <18956-9169151921910054@postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <18956-9169151921910054@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 12, 2025 at 08:03:25AM +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18956 > Logged by: Anudeep Vattikonda > Email address: anudeepvattikonda0404@gmail.com > PostgreSQL version: 17.5 > Operating system: Mac > Description: > > Hi > I am trying to run the below query > select REGEXP_COUNT('cat at the flat', '\Bat\b') ; > I was expecting it to return 2 but I see Postgres is returning 0. I see that > there are two matches, cat and flat. All it should do is to look for the > word at whose left side shoudn't be a word boundary while the right side > should be a word boundary What makes you think that \B/\b has anything to do with word boundary? Docs (https://www.postgresql.org/docs/17/functions-matching.html#FUNCTIONS-POSIX-REGEXP) show: \b - backspace, as in C \B - synonym for backslash (\) to help reduce the need for backslash doubling As far as I can tell pg regexps have nothing related to word boundaries. You could get 2 by changing the regexp to something that actually works: $ select REGEXP_COUNT('cat at the flat', '[a-z]at(?![a-z])'); regexp_count ────────────── 2 (1 row) Best regards, depesz