pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joel Jacobson <joel@compiler.org>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Some regular-expression performance hacking
Date: Fri, 19 Feb 2021 10:26:20 -0500
Message-ID: <3028106.1613748380@sss.pgh.pa.us> (raw)
In-Reply-To: <b16bccc0-3f98-47ad-81aa-699a3e00630d@www.fastmail.com>
References: <1340281.1613018383@sss.pgh.pa.us>
	<85140bfb-516c-449b-8a03-7930abb42b88@www.fastmail.com>
	<1813969.1613250697@sss.pgh.pa.us>
	<913516b8-c3d7-4dea-bf60-d735cf4673f1@www.fastmail.com>
	<2155152.1613358697@sss.pgh.pa.us>
	<99f6cbe0-6e58-4e41-add0-977271a5cf84@www.fastmail.com>
	<2752386.1613595636@sss.pgh.pa.us>
	<5deabab3-a335-4b57-a046-8a9ad8f2f142@www.fastmail.com>
	<12e6381c-adc1-4711-a619-864fb8df969c@www.fastmail.com>
	<2840118.1613671847@sss.pgh.pa.us>
	<2845172.1613674385@sss.pgh.pa.us>
	<b16bccc0-3f98-47ad-81aa-699a3e00630d@www.fastmail.com>

"Joel Jacobson" <joel@compiler.org> writes:
> On Thu, Feb 18, 2021, at 19:53, Tom Lane wrote:
>> (Having said that, I can't help noticing that a very large fraction
>> of those usages look like, eg, "[\w\W]".  It seems to me that that's
>> a very expensive and unwieldy way to spell ".".  Am I missing
>> something about what that does in Javascript?)

> I think this is a non-POSIX hack to match any character, including newlines,
> which are not included unless the "s" flag is set.

> "foo\nbar".match(/([\w\W]+)/)[1];
> "foo
> bar"

Oooh, that's very interesting.   I guess the advantage of that over using
the 's' flag is that you can have different behaviors at different places
in the same regex.

I was just wondering about this last night in fact, while hacking on
the code to get it to accept \W etc in bracket expressions.  I see that
right now, our code thinks that NLSTOP mode ('n' switch, the opposite
of 's') should cause \W \D \S to not match newline.  That seems a little
weird, not least because \S should probably be different from the other
two, and it isn't.  And now we see it'd mean that you couldn't use the 'n'
switch to duplicate Javascript's default behavior in this area.  Should we
change it?  (I wonder what Perl does.)

			regards, tom lane





view thread (38+ messages)  latest in thread

Message-ID: <3028106.1613748380@sss.pgh.pa.us>
Permalink:  ../3028106.1613748380@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3028106.1613748380@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, joel@compiler.org
  Subject: Re: Some regular-expression performance hacking
  In-Reply-To: <3028106.1613748380@sss.pgh.pa.us>
  References: <1340281.1613018383@sss.pgh.pa.us> <85140bfb-516c-449b-8a03-7930abb42b88@www.fastmail.com> <1813969.1613250697@sss.pgh.pa.us> <913516b8-c3d7-4dea-bf60-d735cf4673f1@www.fastmail.com> <2155152.1613358697@sss.pgh.pa.us> <99f6cbe0-6e58-4e41-add0-977271a5cf84@www.fastmail.com> <2752386.1613595636@sss.pgh.pa.us> <5deabab3-a335-4b57-a046-8a9ad8f2f142@www.fastmail.com> <12e6381c-adc1-4711-a619-864fb8df969c@www.fastmail.com> <2840118.1613671847@sss.pgh.pa.us> <2845172.1613674385@sss.pgh.pa.us> <b16bccc0-3f98-47ad-81aa-699a3e00630d@www.fastmail.com> <3028106.1613748380@sss.pgh.pa.us>

* 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