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

in thread Stuck in komplexer regex, at least for me

I feel the need to ask, might it be easier to convert your numbers to the other firm's numbers? Or maybe not try to convert anyone's numbers, but use both yours and theirs and match them up using a database or something?
Maybe if I understood how and why they seem to add 0 in very odd places, it would be easier to figure out how to deal with this.
I'm not a regex person, so this is my stab at this:

`#!/usr/bin/perl
use strict;
# We want to do the following:
#counting starts at 0
# the 0 , 1 digits shoud be untouched
# if the 2 digit is a 0 and the next digit is a 0 remove all 0 untill
+first non 0
# if the 2 digit a 0 and the next is a non 0 remove the 0
# if the 3 digit is a 0 and follows by a 0 then remove all 0 except th
+e 0 at 3 digit
# if the 3 digit is a 0 and the next digit is a non 0 remove only the
+0
# if the 4 digit is a 0 remove it and all following 0 untill non 0
foreach my $number (<DATA>) {
chomp($number);
# print $number . "\n";
my @digits = split("", $number);
my $newnumber;
my $i = 0;
for ($i=0; exists($digits[$i]); $i++) {
# print "I:$i, " . $digits[$i] . "\n";
if ($i < 2) {
# 0, 1 digits should be untouched
$newnumber .= $digits[$i];
next;
} elsif ($i == 2) {
# if the 2 digit is a 0 and the next digit is a 0 remove all 0 u
+ntill first non 0
# if the 2 digit a 0 and the next is a non 0 remove the 0
if ($digits[$i] > 0) {
$newnumber .= $digits[$i];
next;
} elsif (($digits[2] == 0) && ($digits[3] == 0)) {
for(my $j = 2; $digits[$j] == 0; $j++) {
$i++; # we skip this digit
}
$newnumber .= $digits[$i];
} # no need for another else b/c we remove the 0 anyway
} elsif ($i ==3) {
# if the 3 digit is a 0 and follows by a 0 then remove all 0 exc
+ept the 0 at 3 digit
# if the 3 digit is a 0 and the next digit is a non 0 remove onl
+y the 0
if (($digits[3] == 0) && ($digits[4] > 0)) {
next;
} elsif(($digits[3] == 0) && ($digits[4] == 0)){
$newnumber .= $digits[$i];
for (my $j = 4; $digits[$j] == 0; $j++) {
$i++;
}
$newnumber .= $digits[$i];
}
} elsif ($i == 4) {
# if the 4 digit is a 0 remove it and all following 0 untill non
+ 0
if ($digits[4] == 0) {
for (my $j=4; $digits[$j] == 0; $j++) {
$i++;
}
$newnumber .= $digits[$i];
} else {
$newnumber .= $digits[$i];
}
} else {
$newnumber .= $digits[$i];
}
}
print "$number -> $newnumber\n";
}
__DATA__
215000007801
300000324002
890000457651
210004563401
201045139158
`

**I'm sure there is a serious performance hit for not using a regex.**