Yours can be used too, but still have to fix the \D. Adding $ ensure it always match the last number. It should be working fine now. (I have corrected my previous post too).
Code: Select all
name = "xxxx1@gmail.com";
f = findAll(name, ".*?(\\d+)\\D*$", true);
if(!isEmpty(f))
{
num = f[0][1] + 1; //increment num by 1
r = max(length(f[0][1]), length(num)); //check if after added
newnum = right("{num,numberformat,0000000000}", r); //reserve 10 digit and take right digit as many as r
newname = replaceAll(name, "(.*?)(\\d+)(\\D*)$", "$1" + newnum + "$3"); //same regex pattern, but with new capture group and replacement
}