Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Stuck in komplexer regex, at least for me

by xicheng (Sexton)
on Mar 26, 2007 at 23:05 UTC ( [id://606684]=note: print w/replies, xml ) Need Help??


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 ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://606684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-20 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found