http://www.perlmonks.org?node_id=606684


in reply to Re: Stuck in komplexer regex, at least for me
in thread Stuck in komplexer regex, at least for me

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
201045139158
Regards,
Xicheng
  • Comment on Re^2: Stuck in komplexer regex, at least for me

Replies are listed 'Best First'.
Re^3: Stuck in komplexer regex, at least for me
by ultibuzz (Monk) on Mar 27, 2007 at 06:42 UTC

    your right 2 patterns look easyer,

    i am testing atm 5 million numbers and afterwards they will check with the system, then i know if all fit are some fail.

    same testing atm for the regex fanboy pattern ;)

    thx alot for the quick and very good help
    kd ultibuzz



    UPDATE:there is a problem with numbers like

    215100069395
    215100069395
    215100153821
    they shoud change into
    215169395
    215169395
    2151153821
    
    but they remained unchanged

    UPDATE 2:i have it running with an if loop, if digit 2 or 3 is 0 use new pattern else my old one ^^
    this isn't nice at all and i don't like it ;)