pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: rmzgrimes@gmail.com
To: pgsql-docs@lists.postgresql.org
Subject: Re: Unnecessary use of .* in examples
Date: Mon, 01 Feb 2021 09:53:06 +0100
Message-ID: <259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at> (raw)
In-Reply-To: <161215841824.14653.8969016349304314299@wrigleys.postgresql.org>
References: <161215841824.14653.8969016349304314299@wrigleys.postgresql.org>

On Mon, 2021-02-01 at 05:46 +0000, PG Doc comments form wrote:
> Page: https://www.postgresql.org/docs/13/functions-matching.html
> Description:
> 
> In the table for the ~ (and friends) operator, every example has a pointless
> set of '.*' surrounding the text to be matched. These unnecessary operators
> add visual clutter making the examples both harder to read and understand,
> and since they're official examples, they teach bad habits.
> 
> That is to say, 'thomas' ~ 'thom' is the exact same regex as 'thomas' ~
> '.*thom.*' but the first is shorter, easier to read and easier to
> understand, and, presumably, faster as well.
> 
> Operator
> 
> Description
> 
> Example(s)
> 
> text ~ text → boolean
> 
> String matches regular expression, case sensitively
> 
> 'thomas' ~ '.*thom.*' → t
> 
> text ~* text → boolean
> 
> String matches regular expression, case insensitively
> 
> 'thomas' ~* '.*Thom.*' → t
> 
> text !~ text → boolean
> 
> String does not match regular expression, case sensitively
> 
> 'thomas' !~ '.*thomas.*' → f
> 
> text !~* text → boolean
> 
> String does not match regular expression, case insensitively
> 
> 'thomas' !~* '.*vadim.*' → t

I agree that that is comewhat confusing for people who understand
regular expressions.  On the other hand, the example should show some
special characters, so that people who don't know regular expressions
understand that this is more than substring matching.

Perhaps 'thomas' ~ '^thom' and so on?

Yours,
Laurenz Albe






view thread (4+ messages)  latest in thread

Message-ID: <259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at>
Permalink:  ../259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at/
Also on:    postgresql.org/message-id/259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: laurenz.albe@cybertec.at, rmzgrimes@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Unnecessary use of .* in examples
  In-Reply-To: <259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at>

* 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