On Thu, 14 Jun 2007, Martin Barth wrote:
On Thu, 14 Jun 2007 11:04:51 +0100 (WEST)
Jorge Almeida <[EMAIL PROTECTED]> 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 problem is * in your regex. i guess the \D* matches on zero non
digits before "123". so nothing will be done.
Right! Thanks.
--
Jorge Almeida
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/