-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Many thanks to all who responded.  I have been reviewing the code examples 
sent to me and I will work to incorporate them into the next iteration of the 
program.  It's rather funny to me that my 30+ lines of code we're reduced to 
about 4 with some regex's and a small if statement.  Shows I have a long way 
to go, but it's been fun so far.  




On Thursday 29 May 2003 11:36, Rob Dixon wrote:
> Hi Chris.
>
> Please post to the list rather than directly to me. That
> way you should get an answer of some sort even if I don't
> get to it myself. Thanks.
>
> Chris Zimmerman wrote:
> > Hash: SHA1
> >
> > while ( $tmpfile =~ /([^,\s]+):([^,\s]+)/g )
> >
> > Can you help me understand this regex?  I know the first [ ] is $1 and
> > the second is $2, but I am at a loss to see what this does.
>
> Nearly right, but the first ( .. ) demarks $1 and the second one
> demarks $2. The parts enclosed by the sqaure brackets are character
> classes
>
>   [^,\s]
>
> The circumflex '^' negates the class (so that the class will match
> 'not any of the following characters'). Then it's just a comma and
> \s, which matches any 'whitespace' character - tab, linefeed,
> formfeed, carriage-return and space. The character class will
> therefore match anything which is neither whitespace nor a comma.
>
> So the complete regex
>
>   [^,\s]+:[^,\s]+
>
> will match two strings of one or more such characters separated
> by a colon. The two pairs of parentheses capture the strings
> before and after the colon, which should be the email address and
> the file name. Adding the \s into the character class makes the
> regex immune to spaces around the separating commas, as well as
> discarding any trailing spaces and the newline at the end of each
> config record.
>
> Finally the /g modifier in scalar context (which it is, as the
> conditional expression of a 'while' statement) makes the regex
> match just once each time it is executed. It attempts the match
> from the point in the string where the previous match left off.
> This makes it capture one mail address/file name pair for each
> time through the 'while' block.
>
> I hope this is clear.
>
> Rob
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+1kZtkXvEbfjFKqoRAp8LAJ9Bb3wh2OpniHfXwv8yKUJ8LaypEwCghzqi
GpK0c1ktFaJiPmRL8x5hkDY=
=/K3B
-----END PGP SIGNATURE-----


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to