Just another Perl shrine | |
PerlMonks |
Re^2: Stuck in komplexer regex, at least for meby xicheng (Sexton) |
on Mar 26, 2007 at 23:05 UTC ( [id://606684]=note: print w/replies, xml ) | Need Help?? |
Hi, You need an anchor '^' to make sure the matchings start from the beginning of your strings..and your requirements might be written into two patterns which would be much easier to understand(the order of two s/// expressions matters)..
#!/usr/bin/perl use warnings; use strict; while(<DATA>) { s/^(\d\d[1-9])0(?=[1-9])/$1/; s/^(\d\d(?:[1-9]0)?)0+/$1/; print; } __DATA__ 215000007801 300000324002 890000457651 210004563401 201045139158Regards, Xicheng
In Section
Seekers of Perl Wisdom
|
|