From owner-freebsd-questions@FreeBSD.ORG Mon Dec 1 14:13:44 2008 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 263141065670 for ; Mon, 1 Dec 2008 14:13:44 +0000 (UTC) (envelope-from drew@mykitchentable.net) Received: from smtpauth.surewest.net (smtpauth.surewest.net [66.60.130.153]) by mx1.freebsd.org (Postfix) with ESMTP id 08D518FC0C for ; Mon, 1 Dec 2008 14:13:43 +0000 (UTC) (envelope-from drew@mykitchentable.net) Received: from blacklamb.mykitchentable.net (unknown [69.62.230.77]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtpauth.surewest.net (Postfix) with ESMTP id 0FC2A9BF2A; Mon, 1 Dec 2008 06:13:16 -0800 (PST) Received: from [192.168.1.3] (bigdaddy.mykitchentable.net [192.168.1.3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTPSA id 7C5EE164D70; Mon, 1 Dec 2008 06:13:41 -0800 (PST) Message-ID: <4933F108.4050407@mykitchentable.net> Date: Mon, 01 Dec 2008 06:13:28 -0800 From: Drew Tomlinson User-Agent: Thunderbird 2.0.0.18 (Windows/20081105) MIME-Version: 1.0 To: Matthew Seaman References: <4932CA0D.8080109@mykitchentable.net> <4932D91F.5040804@infracaninophile.co.uk> <4932E8A2.6030804@mykitchentable.net> <493385F4.6010809@infracaninophile.co.uk> In-Reply-To: <493385F4.6010809@infracaninophile.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions Subject: Re: Regular Expression Help 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: Mon, 01 Dec 2008 14:13:44 -0000 Matthew Seaman wrote: > Drew Tomlinson wrote: >> Matthew Seaman wrote: > >>> % perl -p -e 's/cn=([^ ,]+) ([^,]+),/cn=$2 $1,/' < foo.txt > >> I still don't really understand *why* the above works but I'm trying >> to pick it apart now. > > The RE breaks down like this: > > /cn=([^ ,]+) ([^,]+),/ > cn= Match literal text 'cn=' > ( capture #1 begin > [^ ,] Character class: anything that is not space or > comma > + At least one of the above > ) end capture #1 > Match a literal space > ( capture #2 begin > [^,] Character class: anything that is not a comma > + At least one of the above > ) end capture #2 > , Match literal comma Thank you for that. You've shown me a new way to look at things. Instead of worrying about what I want to match, determine what marks the beginning and end of what I want to match and use negated character classes to find those end points. I think my regex writing has just gotten better. :) Cheers, Drew -- Be a Great Magician! Visit The Alchemist's Warehouse http://www.alchemistswarehouse.com