Paul M Lieberman wrote:

> $Bill Luebkert wrote:
> 
>> use strict;
>>
>> my $str = '\wwwcopy\default.asp\archive.asp\my.default.asp';
>>
>> $str =~ s/\.(?=.*\..{3,4}$)/_/g;
>> print "$str\n";
>>
>> __END__
> 
> 
> Bill,
> 
> Please explain this interesting [or should I say arcane ;^) ?] bit of 
> regexp.
> 
> I see substituting underscore for a dot followed by something I don't 
> understand, followed by 3 or 4 somethings at the end of the line.

See Extended Patterns in perlre man page or pipe perldoc.bat perlre into 

more or less and page down about 375 lines to 'Extended Patterns'.


Basically you are looking for a zero-width positive look-ahead assertion
which is defined as '(?=pattern)'.  In this case it eliminates the need
to substitute $1 and/or $2 back into the string.

 > Also, why "use strict"?

I test all of the snippets that I post (or state untested if I don't have
time) and I ALWAYS use 'use strict;' as the first line of Perl code.  If
you don't, you're inviting future problems with your code IMO.

-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to