Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6UxR-0003cs-Dh for pgsql-docs@arkaria.postgresql.org; Mon, 01 Feb 2021 08:53:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l6UxQ-00064d-9V for pgsql-docs@arkaria.postgresql.org; Mon, 01 Feb 2021 08:53:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6UxP-00064V-Vb for pgsql-docs@lists.postgresql.org; Mon, 01 Feb 2021 08:53:16 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l6UxM-000244-70 for pgsql-docs@lists.postgresql.org; Mon, 01 Feb 2021 08:53:14 +0000 Received: by mail-ed1-x529.google.com with SMTP id q2so3164432edi.4 for ; Mon, 01 Feb 2021 00:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=UbZ1lPBM2ShZ/96KGTcQGAIa/csTRVTYL7Eyo7HD9dc=; b=tn8vUH2ykm1uHRTvcwwgfmXQq5Yd2ZTnBK710QxUofWLCUtnFv4h+Dp8/3l1kMg9L+ /6d/tGByHt582lhEDoih8/Ki+ghZ00XWjeCuVWCgkvvhuiXLUQurRiuPzvNJ80P8xcTT W34AUSLY449bKksswa3FUWlh0sZJOFrfdzF6Rc8GnaZO0AeRGZs+u+u7RSAC3XgopKSq 4iWP8t7I3gLa1V89hE/4NO7zptMWUDZ961YIZehP39yfF66SSGZX1dGFPp2k+et0cikt 0hWcJhfduvwCC4kAifP+/3eYKRW6ktiqDuZWupSok08XyaTEzgcpkXIVCTPgaH8+6jkP 0p+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=UbZ1lPBM2ShZ/96KGTcQGAIa/csTRVTYL7Eyo7HD9dc=; b=JXtCXQnSe13NYwfWY32Qx3+u09fo+YUq0VxmbouuV2iIzD56W4Ton2P9u/4ZB3IHqt A59vkm6WrzI4cihALD1yilFhDE4nVWhEz1NLEaxBh/ATmF7Ve6xqtwKmMi5Wnit2C4Nu CWrJU8wo2LQMPLWXrq/VKG/psAVD0ILkVVmE87JPzHCAEmXe9E+ZVXRjIl2hDkgocylE KqY9FGxUW1Sk61JD8HiPoYQ6TVxmqMlfTvzLrVqBQibr3irmz6+y00uI44qSghpX1hRM NfFBOC+F1Fex6HvKsjRnA738UlcF0bsOdDgc9Chs7BEvnXZdqBSVVwDGq0iC2M/o35mF RtOw== X-Gm-Message-State: AOAM530ZkNX2pQP70lZBHuLngGZPairkhGm1TA7Iq4qDEc3dlsir61Mw jpFWN3eLxJh7r1s6W3gkmfg8Iw== X-Google-Smtp-Source: ABdhPJyft7tH2+wveqDujaPX9RiRQRdcWTVwDrJOXnfDhAP/H/GXmyWzqc+PBSqF1oW9gBaSDQTwGg== X-Received: by 2002:a05:6402:438d:: with SMTP id o13mr17384829edc.135.1612169590331; Mon, 01 Feb 2021 00:53:10 -0800 (PST) Received: from localhost.localdomain (217-149-173-199.nat.highway.telekom.at. [217.149.173.199]) by smtp.gmail.com with ESMTPSA id e7sm7634902ejb.19.2021.02.01.00.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Feb 2021 00:53:10 -0800 (PST) Message-ID: <259a5d19b504d7cb9bb2f76ea384a045bcc525dc.camel@cybertec.at> Subject: Re: Unnecessary use of .* in examples From: Laurenz Albe To: rmzgrimes@gmail.com, pgsql-docs@lists.postgresql.org Date: Mon, 01 Feb 2021 09:53:06 +0100 In-Reply-To: <161215841824.14653.8969016349304314299@wrigleys.postgresql.org> References: <161215841824.14653.8969016349304314299@wrigleys.postgresql.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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