[pm-h] Regex

Mike Flannigan mikeflan at att.net
Sat Dec 22 14:45:58 PST 2012


On 12/22/2012 3:18 PM, Fraser Baker wrote:
> Hi Y'all:
> I have a four segment string delimited by '::'.
> How can one stop a substitution regex at the first encounter of the 
> '::' symbol?
> How can one say stop the substitution at the second encounter of a the 
> '::' symbol?
> Fraser

This did what I think you wanted to do:


s/^[^:]*::/whatever::/;

s/^([^:]*::)[^:]*::/$1whatever::/;

________________________________________________________



#!/usr/local/bin/perl
use strict;
use warnings;

while (<DATA>) {
#    s/^[^:]*::/whatever::/;
     s/^([^:]*::)[^:]*::/$1whatever::/;
     print;
}

__DATA__
one::two::three::four
one2::two2::three2::four2



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20121222/8a3739a7/attachment.html>


More information about the Houston mailing list