Regular Expression Help

Matthew Seaman m.seaman at infracaninophile.co.uk
Sun Nov 30 22:36:51 PST 2008


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

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                  Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20081201/3013a36c/signature.pgp


More information about the freebsd-questions mailing list