X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4AC4CD1CA06 for ; Thu, 29 Jan 2004 15:50:43 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 84603-05 for ; Thu, 29 Jan 2004 11:50:21 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 240F5D1CADC for ; Thu, 29 Jan 2004 11:50:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i0TFoLpe022883; Thu, 29 Jan 2004 10:50:21 -0500 (EST) To: "Chris Travers" Cc: pgsql-sql@postgresql.org Subject: Re: How to retrieve N lines of a text field. In-reply-to: <010301c3e679$077698b0$5444053d@winxp> References: <010301c3e679$077698b0$5444053d@winxp> Comments: In-reply-to "Chris Travers" message dated "Thu, 29 Jan 2004 22:01:59 +0700" Date: Thu, 29 Jan 2004 10:50:21 -0500 Message-ID: <22882.1075391421@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/265 X-Sequence-Number: 16658 "Chris Travers" writes: > However, this always selects every line but the final one (because %\n seems > to be interpreted to be the largest possible string, while I want it to be > the smallest possible string). I don't think you can solve this in SQL99 regular expressions, but if you use the POSIX-style regex operators, you can write something like "[^\n]*\n" to match exactly one line. There are other features that might help too, such as the counted-match operator "{n}". Read the man page. BTW, I bought a copy of the O'Reilly book "Mastering Regular Expressions" a couple years ago, and it is worth every penny if you do much of anything with regexes. regards, tom lane