Rob Dixon wrote:
It's always confusing when a program written in one language (here, Perl)
creates a program in another (this script is building regular expressions).

Look at the strings those lines are generating.

use strict;
use warnings;

local @ARGV = qw/A B C/;

my $or_pattern = '.*(?:' . join('|', @ARGV) . ')';
my $and_pattern = join('', map{"(?=.*$_)"} @ARGV);

print "Or pattern:  $or_pattern\n";
print "And pattern: $and_pattern\n";

**OUTPUT**

Or pattern:  .*(?:A|B|C)
And pattern: (?=.*A)(?=.*B)(?=.*C)

Now can you understand those as regular expressions? The former uses
non-capturing parentheses (?: ... ) to find any one of the values anywhere in
the string, while the latter uses a lookahead (?= ... ) to find a point in the
string after which all three of the values appear anywhere.

HTH,

Rob
This is VERY clear. thank you understand it now!!!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to