> my $string = 'boy, pig, 123, 123:412adbd, d0g,
> lajdlf134><<_ lkadsf !234,';
>
> if( $string =~ m/,\s*([^,]*),[^,]*$/ ){
> print "$1\n";
> }
How could you guys write this so simple? My regexp was twice this long.
the regexp after \s* tells perl to match anything (0 or more) that is not a
comma, right? how come it did not match pig? pig is also followed by comma,
right? so pig should be captured by ([^,]*), right? I guess perl really looks
for a match starting from the end of the line.
The string actually looks like this:
ABCD1:5C, 2009-04-14 13:01:24, 2009-04-14, 5, 23, ABC, , , -1, 187, 0, 1.2.3.4,
20, lkasd123 as_!23:<<>s @12ff,
My Regexp looks like this:
/\.\s+\d+,\s+\d+,\s+(.*),$/
It matches from the comma at the end of the line up to .4 when you go
backwards. By going as far as this, I can be assured that perl won't find any
more match, but the regexp looks ugly.
What is wrong with my version?
I think if in the future, if perl finds a line which is not ending in a pattern
exactly like my regexp then it will fail, however yours i guess won't.
>
> __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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/