On Fri, 5 Nov 2004, Beckett Richard-qswi266 wrote:
> use strict;
> use warnings;
> my $pat = "abcd<efgh>ijklmnop<qrst>uvwxyz";
> print "\$pat is $pat\n";
> $pat =~ /<(.*)>.*<(.*)>/;
> my ($one, $two) = ($1, $2);
> print "\$one is $one\n\$two is $two\n";

That does work in this case, but it's not terribly robust. If there were a
third angle-bracketed substring, for instance, (or only one) this would no
longer match them correctly.

I'd always use one of the following:

1) $pat = /<([^>]*)>.*<([^>]*)>/;

   This always matches the first two angle-bracketed substrings, ignoring
   any others there might follow.

2) my @matches = ($pat =~ /<([^>]*)>/g);

   This matches any number of angle-bracketed substrings, returning them
   in a list.


TomP

> > -----Original Message-----
> > pattern: abcd<efgh>ijklmnop<qrst>uvwxyz
> > 
> > >From the above pattern, How to find the parameter $1=efgh 
> > and $2=qrst within <>. What is the regex to written in perl?

-------------------------------------------------------------------------
Tom Pollard                                       [EMAIL PROTECTED]
Schrodinger, Inc.                                    646-366-9555 x102
-------------------------------------------------------------------------




_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to