Michael Alipio <[email protected]> asked:
> I have a $string that is separated by , and space;
>
> boy, pig, 123, 123:412adbd, d0g, lajdlf134><<_ lkadsf !234,
>
>
> Now I want to capture the string(s) between last two commas. It consists
> of anything upto 32 characters. that is, right after d0g,\s+ up to the
> last character before the last comma at the end of the line.
#!/usr/bin/perl -w
use strict;
my $string = 'boy, pig, 123, 123:412adbd, d0g, lajdlf134><<_ lkadsf !234,';
if( $string =~ m/,\s*([^,]*),[^,]*$/ ){
print "$1\n";
}
__END__
Depending on the input data size it might worthwhile to look at rindex() and
substr() instead of using a RE.
HTH,
Thomas
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/