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 1mr8NZ-0004GE-Sd for pgsql-general@arkaria.postgresql.org; Sun, 28 Nov 2021 00:49:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mr8NY-00086K-A2 for pgsql-general@arkaria.postgresql.org; Sun, 28 Nov 2021 00:49:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mr8NX-00085S-Aj for pgsql-general@lists.postgresql.org; Sun, 28 Nov 2021 00:49:15 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mr8NU-0006A6-JD for pgsql-general@lists.postgresql.org; Sun, 28 Nov 2021 00:49:14 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 128B25C00D7; Sat, 27 Nov 2021 19:49:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 27 Nov 2021 19:49:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=FwociFh158Iq8PvUEQX3kEqYwWbnHzrT8NzqbjllpaQ=; b=Zop7E8KD T0w8q90DSpZbbrWZllXQm6Vjit7kh1w71UGBa/O13ynxbMdoDe1AWxDC5mGsH29q D8zQQWm7u4clvFKTi6lHtizXaDlXbJdxoBXiTr+AaLWBOWUqaEktULhgZNknk60r sDfANAULr4pGDIY2oinmbogmEnbs3P1MXmUv3Ax12c5u+n5JNJE+ipyy1KsDYDko 34w5QdCeJeVFv2jnq//FmKdQVzdZAlEI6l5ywylItfMfhKPB3t2MPeWf13c8mzfX AMMD08o3MP6c+4JDG+1+/OdAlVd+uANKq8hg6ViTYYdfxdsfJPzT/8gij7M1CqMX IYbHlpOC159TAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrheehgddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeevjedu feeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 27 Nov 2021 19:49:10 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 4CC702A0806; Sat, 27 Nov 2021 21:49:07 -0300 (-03) Date: Sat, 27 Nov 2021 21:49:07 -0300 From: Alvaro Herrera To: Shaozhong SHI Cc: pgsql-general Subject: Re: Match 2 words and more Message-ID: <202111280049.bmeoep6puysk@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Nov-28, Shaozhong SHI wrote: > this is supposed to find those to have 2 words and more. > > select name FROM a_table where "STREET_NAME" ~ '^[[:alpha:]+ ]+[:alpha:]+$'; > > But, it finds only one word as well. How about something like this? '^([[:<:]][[:alpha:]]+[[:>:]]( |$)){2}$' You have: - the ^ is a constraint that matches start of string - you have a ( ... ){2}$ construct which means "match exactly twice" and then match end-of-string - Inside the parens of that construct, you match: - [[:<:]] which means start-of-word - [[:alpha:]]+ which means "a non-empty set of alphabetical chars" - [[:>:]] which means end-of-word - ( |$) for "either a space or end-of-string" You can perhaps simplify by removing the [[:<:]] and [[:>:]] constraints, so '^([[:alpha:]]+( |$)){2}$' To mean "between two and four", change the {2} to {2,4}. If you want "two or more", try {2,}. You could change the ( |$) to ([[:white:]]+|$) in order to accept more than one space between words, or combinations of space and tabs and newlines and so on. With a decent set of data, you could probably notice some other problems in this regexp, but at least it should be a decent start. > It appears that regex is not robust. Nah. -- Álvaro Herrera 39°49'30"S 73°17'W — https://www.EnterpriseDB.com/