I'm trying to figure out how to use regex to replace several possible strings in filenames and am not even sure it's possible to do so. Here's what I have:
A filename with a string of text and a number 1.jpg
A filename with a string of text and a number 1 and more text.jpg
A filename with a string of text and a number 17.jpg
A filename with a string of text and a number 17 and more text.jpg
A filename with a string of text and a number 105.jpg
A filename with a string of text and a number 105 and more text.jpg
I would like grab everything prior to the number and replace it. Easy enough, I can do this with no problem.
I would like to prefix 0s to each number that is less than 3 digits. For example, a 1-digit number should have '00' prefixed. A 2-digit number should have '0' prefixed. A 3-digit number should not have anything prefixed. Final result is that every number is 3-digits.
I would like to preserve everything after the number.
So the final result should be:
New replacement text 001.jpg
New replacement text 001 and more text.jpg
New replacement text 017.jpg
New replacement text 017 and more text.jpg
New replacement text 105.jpg
New replacement text 105 and more text.jpg
I've been working so far with structures similar to:
(.*) ((\d{3})(.*)|(\d{2})(.*)|(\d{1})(.*))
but what I don't know is how to replace group to group, or if it's even possible. For example:
(\d{3}) would be replaced by \2
(\d{2}) would be replaced by 0\2
(\d{1}) would be replaced by 00\2
I'm starting to think this is not possible in a single step. Can anyone help out here?