If you can find an entire series of numbers with GREP in a script, you should be able to split them into an array, loop through them to compare each number with the preceding number, then add them to a new array. So if the first 3 of the current number match the first 3 of the preceding number, only add the last 3 numbers to the new array. Otherwise, add the number as is (hopefully that makes sense).
I’m extra bored today, so I threw together a function to handle the number checking (I’m sure there’s a cooler way to do this, but this seems to work). If the function works as you expect, you could expand the script to loop through multiple number series in the document, feed them to this function, and use the returned array to update the document.
var sourceNumbers = [405354, 405358, 405359, 405369, 305046, 305047, 405360, 405381, 405382, 405378];
var numbers = removeCommonPrefix(sourceNumbers);
$.writeln(numbers);
function removeCommonPrefix(numbers){
var updatedNumbers = [];
var i = numbers.length-1;
while(i>=1){
var currentNumber = numbers[i];
var currentNumberPrefix = numbers[i].toString().slice(0,3);
var preceedingNumberPrefix = numbers[i-1].toString().slice(0,3);
var numberSuffix = numbers[i].toString().slice(3,6);
if(currentNumberPrefix==preceedingNumberPrefix){
var number = numberSuffix;
}
else{
var number = currentNumber;
}
updatedNumbers.unshift(number);
i--;
}
//the first number will always need the initial 3, so at the end of the loop add it to the start
updatedNumbers.unshift(numbers[0]);
return updatedNumbers;
}