pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Change regex \D and \W shorthands to always match newlines.
Date: Thu, 25 Feb 2021 18:29:31 +0000
Message-ID: <E1lFLOF-0005DV-Gu@gemulon.postgresql.org> (raw)

Change regex \D and \W shorthands to always match newlines.

Newline is certainly not a digit, nor a word character, so it is
sensible that it should match these complemented character classes.
Previously, \D and \W acted that way by default, but in
newline-sensitive mode ('n' or 'p' flag) they did not match newlines.

This behavior was previously forced because explicit complemented
character classes don't match newlines in newline-sensitive mode;
but as of the previous commit that implementation constraint no
longer exists.  It seems useful to change this because the primary
real-world use for newline-sensitive mode seems to be to match the
default behavior of other regex engines such as Perl and Javascript
... and their default behavior is that these match newlines.

The old behavior can be kept by writing an explicit complemented
character class, i.e. [^[:digit:]] or [^[:word:]].  (This means
that \D and \W are not exactly equivalent to those strings, but
they weren't anyway.)

Discussion: https://postgr.es/m/3220564.1613859619@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7dc13a0f0805a353cea0455ed95701322b39d4dd

Modified Files
--------------
doc/src/sgml/func.sgml                             | 28 +++++++++++++++-------
src/backend/regex/re_syntax.n                      |  7 +++++-
src/backend/regex/regcomp.c                        |  6 ++---
.../modules/test_regex/expected/test_regex.out     | 12 ++++++----
4 files changed, 36 insertions(+), 17 deletions(-)



Message-ID: <E1lFLOF-0005DV-Gu@gemulon.postgresql.org>
Permalink:  ../E1lFLOF-0005DV-Gu@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lFLOF-0005DV-Gu@gemulon.postgresql.org

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Change regex \D and \W shorthands to always match newlines.
  In-Reply-To: <E1lFLOF-0005DV-Gu@gemulon.postgresql.org>
  References: <E1lFLOF-0005DV-Gu@gemulon.postgresql.org>

* 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