Re: Bizarre behavior of \w in a regular expression bracket construct

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Joel Jacobson <joel@compiler.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2021-02-21T16:06:51Z
Lists: pgsql-hackers
On 2021-Feb-21, Joel Jacobson wrote:

>    regex    | engine |        deduced_ranges
> ------------+--------+-------------------------------
> ^([a-z])$  | pg     | [a-z]
> ^([a-z])$  | pl     | [a-z]
> ^([a-z])$  | v8     | [a-z]
> ^([\d-a])$ | pg     |
> ^([\d-a])$ | pl     | [-0-9a]
> ^([\d-a])$ | v8     | [-0-9a]
> ^([\w-;])$ | pg     |
> ^([\w-;])$ | pl     | [-0-9;A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w-;])$ | v8     | [-0-9;A-Z_a-z]
> ^([\w-_])$ | pg     | [0-9A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w-_])$ | pl     | [-0-9A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w-_])$ | v8     | [-0-9A-Z_a-z]
> ^([\w])$   | pg     | [0-9A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w])$   | pl     | [0-9A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w])$   | v8     | [0-9A-Z_a-z]
> ^([\W])$   | pg     |
> ^([\W])$   | pl     | [\x01-/:-@[-^`{-©«-´¶-¹»-¿×÷]
> ^([\W])$   | v8     | [\x01-/:-@[-^`{-ÿ]
> ^([\w-a])$ | pg     | [0-9A-Z_-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w-a])$ | pl     | [-0-9A-Z_a-zªµºÀ-ÖØ-öø-ÿ]
> ^([\w-a])$ | v8     | [-0-9A-Z_a-z]

It looks like the interpretation of these other engines is that [\d-a]
is the set of \d, the literal character "-", and the literal character
"a".  In other words, the - preceded by \d or \w (or any other character
class, I guess?) loses its special meaning of identifying a character
range.

This one I didn't understand:
> ^([\W])$   | pg     |

-- 
Álvaro Herrera       Valdivia, Chile
"Porque francamente, si para saber manejarse a uno mismo hubiera que
rendir examen... ¿Quién es el machito que tendría carnet?"  (Mafalda)



Commits

  1. Doc: remove src/backend/regex/re_syntax.n.

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

  3. Allow complemented character class escapes within regex brackets.