Next | Regular Expression Mastery | 48 |
(?=...) and (?!...) are similar to \b and \B.
They look ahead in the string to see if what follows matches ...
If so, they succeed, but don't advance the cursor
Example: Split an email header into fields:
Received: from ni-s.u-net.com ([193.119.182.90] helo=bactrian.ni-s.u-net.com)
by he101war.uk.vianw.net with esmtp (Exim 3.22 #5)
id 17H8J0-0005po-00; Sun, 09 Jun 2002 20:24:51 +0100
Content-Disposition: inline
Content-Transfer-Encoding: binary
MIME-Version: 1.0
X-Mailer: Id: //depot/mail/tkmail#119 /Perl5.008 Mail::Internet v1.46
Subject: Re: Standard layers, documentation
In-Reply-To: <20020609191647.GE31617@ool-18b93024.dyn.optonline.net> from
Michael G Schwern on Sun, 09 Jun 2002 15:16:47 -0400
Content-Type: text/plain; charset="UTF-8"
To: schwern@pobox.com
Wrong: split /\n/
(Consider the Received line for example)
Also wrong: split /\n\S/
Next | Copyright © 2002 M. J. Dominus |