I’m working with fixed-length field data, and I need to shorten the decimal places of a series of numbers to only two decimal places. It is nothing but zeroes after the decimal, so it’s easy enough to write a regex that will trigger on it. The problem is, I need to replace the extra zeroes with spaces. I know I can save a subexpression and recall it in the replacement, but is there a way to count the number of zeroes removed and recall that? I’m just using the regex in Notepad++’s replace window.
I’m working with fixed-length field data, and I need to shorten the decimal places
Share
I’ve found something that works here.
search string:
([.]00[ ]*)0replace string:
\1(There’s a space following the 1)What this does is find the .00, followed by any number of spaces, followed by a zero. It then replaces that with the .00 and the spaces, followed by a space. Each time it is run, it replaces one more of the extra zeroes with a space. It works, but can anyone think of something that only has to be run once? This worked in this case, but I’ve had other times when I wished regex could count.