SOLVED: renumbering between '.'s with initial pad difference

A swapping-ground for Regular Expression syntax

SOLVED: renumbering between '.'s with initial pad difference

Postby olwynn » Mon Oct 18, 2010 8:58 pm

Hi All

Sorry to post what is likely a simple problem, but I'm a little stumped and definitely new to regular expressions. I am having difficulty with file sequences automatically spit out of software in a format I can't change. The files are sequentially numbered as such:

file_1_name.01.tif
file_1_name.02.tif
file_1_name.03.tif
..
file_1_name.101.tif
file_1_name.102.tif

The program they are destined for required the numeric sequence to be between to '.'s to be read properly, but I need to give the sequence to another program and it's choking on the differing amounts of pad.

The easiest way forward that I can see is a way to use regular expressions to insert an additional 0 immediately following the first '.' in order to unify the pad to three digits? I'm assuming that this can be articulated as well in the event that I end up with 4 digits in a longer sequence.

I have tried using the numbering(10) section, but, because of the way windows interprets the filenames, they renumber wrong (.100.tif follows .10.tif for example). I also cannot use the sort by date function to reorder the files as they are not necessarily created sequentially.

Here's hoping someone's got an easy solution and thanks in advance.
Richard
Last edited by olwynn on Mon Oct 18, 2010 10:24 pm, edited 1 time in total.
olwynn
 
Posts: 3
Joined: Mon Oct 18, 2010 4:57 pm

Re: Help!: renumbering between '.'s with initial pad difference

Postby olwynn » Mon Oct 18, 2010 9:35 pm

Update:
moving forward slowly...

I've got

MATCH: (.+?\.)(\d{2}\.)
REPL: \10\2

which grabs everything up to the first dot and stores it for later recall and a modified version of another renumbering expression listed in this forum. I'm now capturing the correct files and prepending a zero to the first extension, but I've got a double dot before the final file extension. Any thoughts? Is there a way to truncate a replace reference to return all but the last character?
olwynn
 
Posts: 3
Joined: Mon Oct 18, 2010 4:57 pm

Re: Help!: renumbering between '.'s with initial pad difference

Postby olwynn » Mon Oct 18, 2010 10:24 pm

Found a note that Stefan gave to someone else which neatly solved my problem. I hadn't realized that the position of the search condition with respect to the round bracket impacted the inclusion of the condition.

I've now got:
MATCH: (.+?\.)(\d{2})\.
REPLACE: \10\2

and get the correct results that I was hoping for.
Original Filenames:
file_1_name.01.tif
file_1_name.02.tif
file_1_name.03.tif
..
file_1_name.101.tif
file_1_name.102.tif

Renamed:
file_1_name.001.tif
file_1_name.002.tif
file_1_name.003.tif
..
file_1_name.101.tif
file_1_name.102.tif

Not sure if this solution is extensible to a further digit without doing a separate pass, but it'll serve for the moment. Hopefully it's useful to someone else.

cheers
Richard
olwynn
 
Posts: 3
Joined: Mon Oct 18, 2010 4:57 pm


Return to Regular Expressions