I.B. wrote:
> sorry, I didn't fraze my question correctly.
                  ^^^^^
                  phrase

> example :
> $line="abcxabcxxabcxxxabc";
>
> how to match everything beofre "xxx" but not xxx itself?
> the answer i got is to use lookaheads:
>
> my $line = "abcxxabcxxxabc";
> if ($line =~ m{(.*?(?:(?!xxx).))xxx}){
>     print "matched: $1\n";
> }
> else{
>     print "failed\n";
> }

Your expression is too complicated:

if ( $line =~ /(.*?)xxx/ ) {

would accomplish the same thing.

$ perl -le'$_ = "abcxabcxxabcxxxabc"; print $1 if /(.*?(?:(?!xxx).))xxx/'
abcxabcxxabc
$ perl -le'$_ = "abcxabcxxabcxxxabc"; print $1 if /(.*?)xxx/'
abcxabcxxabc




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

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


Reply via email to