From owner-freebsd-questions@FreeBSD.ORG Tue Sep 27 02:34:18 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 000781065670 for ; Tue, 27 Sep 2011 02:34:17 +0000 (UTC) (envelope-from grarpamp@gmail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 900D28FC0A for ; Tue, 27 Sep 2011 02:34:17 +0000 (UTC) Received: by wyj26 with SMTP id 26so4758922wyj.13 for ; Mon, 26 Sep 2011 19:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=h77Y8yeBH6K3Tzi+nXJTM1jp4WfqNPlTnyQc7VOaIcw=; b=YBxrCZenb309J3gs1fx3KXeFZ1CzW5JSXOVXVrObHWCUm7/72+Ffidcd5BMptxrzM3 BQQ16Dmt3E313stAJIZWtkVXxJBbivlT+ea6KtCF1TbpN4bFHXiSrZyoZvCsHLm+qFOn RnMTwMyJ80doIc8kQMErFVrwF6Hbmwfv5IC44= MIME-Version: 1.0 Received: by 10.227.202.209 with SMTP id ff17mr6766787wbb.92.1317088971700; Mon, 26 Sep 2011 19:02:51 -0700 (PDT) Received: by 10.180.80.2 with HTTP; Mon, 26 Sep 2011 19:02:51 -0700 (PDT) Date: Mon, 26 Sep 2011 22:02:51 -0400 Message-ID: From: grarpamp To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 Subject: Regex Wizards X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Sep 2011 02:34:18 -0000 Under the ERE implementation in RELENG_8, I'm having trouble figuring out how to group and backreference this. Given a line, where: If AAA is present, CCC will be too, and B may appear in between. If AAA is not present, neither CCC or B will be present. DDDD is always present. Junk may be present. Match good lines and ouput in chunks. echo junkAAAABCCCDDDDjunk | \ This works as expected: sed -E -n 's,^.*(AAAB?CCC)(DDDD).*$,1 \1 2 \2,p' 1 AAABCCC 2 DDDD But making the leading bits optional per spec does not work: sed -E -n 's,^.*(AAAB?CCC)?(DDDD).*$,1 \1 2 \2,p' 1 2 DDDD Nor does adding the usual grouping parens: sed -E -n 's,^.*((AAAB?CCC)?)(DDDD).*$,1 \1 2 \2,p' 1 2 How do I group off the leading bits? Or is this a limitation of ERE's? Or a bug? Thanks.