The following examples show a few applications of regular expressions. Please note that some of the example problems may be solved easier by using the simple replacement mode of SDLRename. The purpose of these examples is to show how to work with regular expressions.

Example 1: Rename all files having the extension .jpeg to .jpg and replace all umlauts by two-character combinations.

Search Expression: .*\.jpeg$
Replacement Expression: @Y@1.jpg

Explanation: You have to search for all filenames ending with the substring .jpeg. This can be achieved by using the regular expression \.jpeg$. However, this will not allow you to access the first part of the filename for replacing umlauts by ASCII character combinations. In order to access the first part of a file name we have to add an additional regular expression token which matches all characters before the .jpeg expression; .* is suitable for this purpose. So we use the following regular expression, which consists of two tokens: .*\.jpeg$. The first part of the file name is matched by the first token, which is converted by the @Y modifier (replace umlauts by 2-character combinations) and reinserted into the renamed filename:

Example 2: Rename all files whose filename starts with a numeric string and insert the current date after the numeric string.

Search Expression: ^[0-9]+
Replacement Expression: @2_<dyyyy-mm-dd>_

Explanation: In order to find a numeric string we use the expression [0-9]+ which means "at least one character of the set 0 to 9". So this expression will match any numeric (decimal) string. In order to find only those numeric strings which are at the beginning of the filename, we have to add the caret ^, which forces the numeric string to become the first substring in the filename. This search string consists of two tokens: the first token is the caret, the second token denotes the numeric string. In order to reinsert the numeric string in the replacement expression we use the token identifier @2 followed by _<dyyyymmdd>_ which inserts the current date.

In summary, a filename such as 129Testname.zip will be translated to 129_20021023_Testname.zip (assuming that this operation takes place on Oct-23, 2002).

Last Update: 2006-Nov-01