Subtracting (or "subtracting") in regular expressions?

A swapping-ground for Regular Expression syntax

Subtracting (or "subtracting") in regular expressions?

Postby RealGrouchy » Sat Jul 03, 2010 7:05 pm

Hi there,

I've been very satisfied with BRU, after http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=689, in which I was able to add a fifth initial digit to the "IMGP1234.jpg" filename of my photos.

A complication of this is that I have to be very careful not to let old photos onto the card, because it will start counting from the old photo's number, if the last four digits are higher than the actual most recent photo I've taken. (It actually doesn't recognize renamed photos, so when I rename them I have to remember not to rename the newest photo and to leave that on the card).

This happened on a recent photo shoot. I ran out of space on my main memory card, and the backup card had some old photos, so my filenames jumped from IMPG21715 to 25406.

Double unfortunately, I only noticed this now (at 25684) and I've already filed a bunch of the photos, so I can't simply select all the new photos on the memory card and renumber them starting at 21716.

Is it possible to use regular expressions to subtract? I.e. to look for photos starting with 25xxx and subtract 3690 from the number? I believe this isn't possible. If it is please let me know, as it will save me a ton of work!

Since it's only a couple hundred photos, I think I can use formulae to scan my hard drive for these photos and renumber them 'manually' (I.e. replace digits individually). Luckily it skipped by 3690, which ends in a zero, so I should be able to renumber them by simply changing the digit. I know that only the badly-numbered photos are the only ones starting with IMGP25xxx, so filtering them isn't a problem.

Instead of making 28 separate searches (i.e. change 2540x to 2171x, change 2541x to 2172x, etc.), I can do the tens first (i.e. change 25x0x to 25x1x, change 25x1x to 25x2x), then the hundreds (i.e. change 254xx to 217xx, etc.). This will reduce it to 13 searches.

Except as far as I can tell I have to do them individually, which will leave me with two sets of any particular tens values.

The solution to this is to first change the 90's, and change them to the final new number (i.e. 2549x becomes 2180x instead of 2540x or 2550x), which will be unique. Then I can go about the other 9 searches for the tens and the other 3 searches for the 100s. So 14 total renames.

So the list of searches to conduct would be (in this order):

Rollover tens:
Change 2559x to 2190x
Change 2549x to 2180x

Other tens:
Change 25x8x to 25x9x
Change 25x7x to 25x8x
Change 25x6x to 25x7x
Change 25x5x to 25x6x
Change 25x4x to 25x5x
Change 25x3x to 25x4x
Change 25x2x to 25x3x
Change 25x1x to 25x2x
Change 25x0x to 25x1x

Hundreds:
Change 254xx to 217xx
Change 255xx to 218xx
Change 256xx to 219xx

This makes sense, right?

To implement this, I use the following code GMA provided in my previous thread, which preserves any text that may have been added before or after the filename.

NINETIES
(.*)(IMGP)(2559)([0-9]{1}(?![0-9]))(.*)
\1\22190\4\5

(.*)(IMGP)(2549)([0-9]{1}(?![0-9]))(.*)
\1\22180\4\5

OTHER TENS
(.*)(IMGP25)([0-9]{1})(8)([0-9]{1}(?![0-9]))(.*)
\1\2\39\5\6

(.*)(IMGP25)([0-9]{1})(7)([0-9]{1}(?![0-9]))(.*)
\1\2\38\5\6

(.*)(IMGP25)([0-9]{1})(6)([0-9]{1}(?![0-9]))(.*)
\1\2\37\5\6

(.*)(IMGP25)([0-9]{1})(5)([0-9]{1}(?![0-9]))(.*)
\1\2\36\5\6

(.*)(IMGP25)([0-9]{1})(4)([0-9]{1}(?![0-9]))(.*)
\1\2\35\5\6

(.*)(IMGP25)([0-9]{1})(3)([0-9]{1}(?![0-9]))(.*)
\1\2\34\5\6

(.*)(IMGP25)([0-9]{1})(2)([0-9]{1}(?![0-9]))(.*)
\1\2\33\5\6

(.*)(IMGP25)([0-9]{1})(1)([0-9]{1}(?![0-9]))(.*)
\1\2\32\5\6

(.*)(IMGP25)([0-9]{1})(0)([0-9]{1}(?![0-9]))(.*)
\1\2\31\5\6

HUNDREDS
(.*)(IMGP)(254)([0-9]{2}(?![0-9]))(.*)
\1\2217\4\5

(.*)(IMGP)(255)([0-9]{2}(?![0-9]))(.*)
\1\2218\4\5

(.*)(IMGP)(256)([0-9]{2}(?![0-9]))(.*)
\1\2219\4\5


It'd be nice if someone can look over my logic and tell me my plan makes sense. I think it does, but I'd hate to find out I've screwed it up irrevocably.

Cheers,

- RG>
RealGrouchy
 
Posts: 6
Joined: Mon May 18, 2009 5:44 am

Re: Subtracting (or "subtracting") in regular expressions?

Postby Stefan » Sat Jul 03, 2010 10:05 pm

>Is it possible to use regular expressions to subtract?
No.

FROM: TO:
IMPG25406 IMPG21716
IMPG25407 IMPG21717
...

DO:
- load copies of your files into BRU
- scroll down to "IMPG25406" and select till the end (click on "IMPG25406" , hold Shift-key and press END-key)
(or use Selection(12) with "IMPG25*" as pattern. Then click into the file list to see if this selection action works. Select then this files by pressing Ctrl+A)

Once the right '278' files to rename are selected:
- Remove(5) [X] Digits
- Numbering(10) Suffix, Start 21716
Take an look on the NewName column, if it looks as you want press on Rename, an dialog tells you that '278' files will be renamed.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Subtracting (or "subtracting") in regular expressions?

Postby RealGrouchy » Sun Jul 04, 2010 3:40 am

Thanks, Stefan.

Renumbering them wouldn't quite work because some numbers are skipped/deleted.

I ended up doing it the way I suggested above and got it done in about 50 minutes, which is less time than I worried it might be (BRU crashed nearly each time when I tried to edit the formula, probably from having 21000 files selected in a few hundred subfolders).

It had been a while since I had bulk renamed stuff across a wide swath of my filesystem, and I had forgotten how straightforward it was (even if it did take a bit of time).

I also edited the formulae above to reflect corrections I made to some errors I encountered.

Thanks again to BRU for making this possible in the first place!

- RG>
RealGrouchy
 
Posts: 6
Joined: Mon May 18, 2009 5:44 am


Return to Regular Expressions