From: hubert depesz lubaczewski <depesz@depesz.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: anudeepvattikonda0404@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18956: Observing an issue in regexp_count()
Date: Thu, 12 Jun 2025 16:05:34 +0200
Message-ID: <aEreruE-8drtSsKt@depesz.com> (raw)
In-Reply-To: <1203062.1749736486@sss.pgh.pa.us>
References: <18956-9169151921910054@postgresql.org>
<aErDmEWoyiNrhY1M@depesz.com>
<1203062.1749736486@sss.pgh.pa.us>
On Thu, Jun 12, 2025 at 09:54:46AM -0400, Tom Lane wrote:
> hubert depesz lubaczewski <depesz@depesz.com> writes:
> > On Thu, Jun 12, 2025 at 08:03:25AM +0000, PG Bug reporting form wrote:
> >> 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?
>
> Indeed, they do not.
>
> > As far as I can tell pg regexps have nothing related to word boundaries.
>
> Sure we do, see "Regular Expression Constraint Escapes":
>
> https://www.postgresql.org/docs/current/functions-matching.html#POSIX-CONSTRAINT-ESCAPES-TABLE
>
> Unfortunately, since these are all way outside the POSIX regexp
> standard, different systems have implemented these extensions
> differently. I don't doubt that \B/\b mean word boundaries
> in some other system.
Oh, Missed that. Thanks.
So the regexp can be rewritten to:
=$ select REGEXP_COUNT('cat at the flat', '\Yat\M');
regexp_count
──────────────
2
(1 row)
Best regards,
depesz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: depesz@depesz.com, tgl@sss.pgh.pa.us, anudeepvattikonda0404@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18956: Observing an issue in regexp_count()
In-Reply-To: <aEreruE-8drtSsKt@depesz.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox