summaryrefslogtreecommitdiff
path: root/src/backend/regex/re_syntax.n
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-02-25 13:29:06 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-02-25 13:29:06 -0500
commit7dc13a0f0805a353cea0455ed95701322b39d4dd (patch)
tree0973b2d140efa40a40512778b9ae1a66eac19242 /src/backend/regex/re_syntax.n
parent2a0af7fe460eb46f9af996075972bf7c2e3f211d (diff)
downloadpostgresql-7dc13a0f0805a353cea0455ed95701322b39d4dd.tar.gz
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
Diffstat (limited to 'src/backend/regex/re_syntax.n')
-rw-r--r--src/backend/regex/re_syntax.n7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/regex/re_syntax.n b/src/backend/regex/re_syntax.n
index 1afaa7cce7..93830fd100 100644
--- a/src/backend/regex/re_syntax.n
+++ b/src/backend/regex/re_syntax.n
@@ -804,7 +804,7 @@ and bracket expressions using
\fB^\fR
will never match the newline character
(so that matches will never cross newlines unless the RE
-explicitly arranges it)
+explicitly includes a newline)
and
\fB^\fR
and
@@ -817,6 +817,11 @@ ARE
and
\fB\eZ\fR
continue to match beginning or end of string \fIonly\fR.
+Also, the character class shorthands
+\fB\eD\fR
+and
+\fB\eW\fR
+will match a newline regardless of this mode.
.PP
If partial newline-sensitive matching is specified,
this affects \fB.\fR