Regular expression syntax ?

Get help with installing and running FastPictureViewer: ask questions here. Please do not post presumed bug reports or suggestions here.

Regular expression syntax ?

Postby simonfbarnes on Tue Dec 14, 2010 4:05 am

I can't find anything on the site that describes the syntax for using regular expressions in renaming. I know there is an example in the context menu: {FileName}{RegEx:(_)?(.*?)(_)?([0-9]+)?$}{3}{4}{1}{2} which reorders the parts of the name, but this still leaves one to guess that "RegEx: applies to the filename (it seems not)
simonfbarnes
 
Posts: 7
Joined: Fri Mar 12, 2010 3:53 pm

Re: Regular expression syntax ?

Postby Axel on Sun Dec 19, 2010 4:28 am

The program use standard ECMAScript regular expressions as part of the most advanced options of its built-in file Rename function (F2).

The example in the context menu transforms file names in the form _ABC1234.jpg into 1234_ABC.jpg, something impossibe to do with standard renaming. The {RegEx:...} part defines the various captures (i.e. splits the file name down to various components), the rest, {3}{4}{1}{2}, specifies the how the resulting name should be built from the various captured components.

You can insert any other substitution variable or litteral parts in the template, say

Code: Select all
{RegEx:(_)?(.*?)(_)?([0-9]+)?$}MyImage#{4}-HasSuffix-{2}

will transform "_ABC1234" into "MyImage#1234-HasSuffix-ABC".

The example regular expression "(_)?(.*?)(_)?([0-9]+)?$" splits the string "_ABC1234" into

0: (_ABC1234)
1: (_)
2: (ABC)
3: ()
4: (1234)

It also splits "ABC_1234" into

0: (ABC_1234)
1: ()
2: (ABC)
3: (_)
4: (1234)

{3}{4}{1}{2} then gives 1234_ABC and _1234ABC, respectively. These are just sample illustrating some manipulations.

Once you have your capture groups set up, it's just a matter of re-assembling the parts as you see fit.

Regular expressions are very powerful and let users create very complex renaming schemes, but the syntax is a bit awkward to say the least... Full documentation here: http://msdn.microsoft.com/en-us/library/bb982727.aspx.

You don't need the {FileName} part in the template for this to work. The {FileName} variable simply represents the original file name, so you can write "My file is named {FileName}" and this will translate to ""My file is named _ABC1234" as you'd expect.

For readers stumbling on this and wondering what we are talking about, FastPictureViewer Professional supports renaming templates where users can define rename "presets" and apply them quickly with the F2 function key, the standard Windows rename shortcut.

By default the renaming function works as anyone expects: press F2, edit the name, press Enter and you are done. In addition to this standard functionality, the program let users create presets that go far beyond this, for example it is possible to automatically insert the current date or some EXIF information in the new file name, using simple substitution variables like for example "{ISOSpeed}", which will be replaced by a number representing the camera ISO setting. The program also support advanced renaming features involving sophisticated techniques described above.

We have a renaming tutorial online on our help page at http://www.fastpictureviewer.com/help/.

EDIT: while playing with the renaming template editor I noticed that it did not save the template being edited, in some circumstances. The issue was fixed and the new installers (1.3.173.1) should correct this occasional problem.
Axel
Site Admin
 
Posts: 748
Joined: Thu Nov 06, 2008 1:54 am
Location: Geneva, Switzerland

Re: Regular expression syntax ?

Postby jlindsey on Thu Jan 19, 2012 6:37 pm

WOW Axel that was helpful. I'm seeing that regular expressions are really powerful, but I grew up with assembler and pascal. Anyway I was just hunting for pulling the last 2 or three characters from the file-name, but I'm guessing what I got will work fine. Maybe a few more "Simple" examples would be helpful. Thanks

D{DateTaken:6}T{DateTaken:11}_{RegEx:(_)?(.*?)(_)?([0-9]+)?$}{4}
jlindsey
 
Posts: 3
Joined: Thu Jan 12, 2012 6:01 pm

Re: Regular expression syntax ?

Postby Axel on Fri Jan 20, 2012 6:10 am

selecting the last N, say 3, characters of a filename should be easy

You want to skip zero or more occurences of any any leading characters, so start with

.*

Then you want to capture 3 characters so you start a capture group () with 3 dots inside

(...)

then you can add a $ sign to tell the group should be at the end.

.*(...)$

There are probably a number of other ways. The above will not match 1 and 2 characters file name, only 3 and up, and the last 3 characters will be captured.

You can find good info on regular expressions on the following site:

http://www.regular-expressions.info/tutorial.html

Have fun!

PS: from your example I see that I could add a couple of extra "date time" formatting presets, like ISO 8601
Axel
Site Admin
 
Posts: 748
Joined: Thu Nov 06, 2008 1:54 am
Location: Geneva, Switzerland


Return to User-to-User



cron