Jorge Almeida wrote:
I'm missing something about Perl's regexp:
1 #!/usr/bin/perl -w
2 use strict;
3 my $s=<STDIN>;
4 $s=~s/\D*//;
5 $s=~s/\D*//;
6 print "$s\n";
When input is 'a123b', I get '123b', but I expected '123'. I know I
can substitute line 4 by '$s=~s/\D*//g;' and comment out line 5. It will
work then, but that is not the point. I could also substitute line 5 by
'$s=~s/\D+//;' and it would also work...
The * quantifier allows for zero or more occurrences of the pattern, so
the regex successfully matches zero non-digits at the start of the
string and the substitution has no effect.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/