Delete characters after first letter to period

Advanced Renamer forum
#1 : 13/04-18 20:56
Todd
Todd
Posts: 2
I've browsed the forums and haven't found what I need, but maybe missed it. I have a bunch of files that are in the format of firstname.lastname.jpg and want to end up with firstinitiallastname.jpg. In other words I need to strip out all of the characters after the first letter up to and including the period in the middle of the file name. The length of characters between the first letter and the middle period varies greatly from file to file.

For example, I want:
clara.oswald.jpg
river.song.jpg
will.riker.jpg

to become:
coswald.jpg
rsong.jpg
wriker.jpg

I see how to remove the period character but I'm not figuring out on my own to how to leave the first letter and stop at the beginning of what is a last name.

Thanks.


13/04-18 20:56
#2 : 13/04-18 22:51
Ronald Andersson
Ronald Andersson
Posts: 3
Reply to #1:
For such needs (as for most advanced renaming) you will need to use 'regular expressions' in your text replacement method. So you start by using the "Replace" command to open the method editor and click the tick-box for "Use regular expressions". Then you enter suitable expressions into the fields for "Text to be replaced:" and "Replace with:" as follows.

Text to be replaced:
(.)[^\.]*\.

The parenthesized period means that we accept the first character whatever it is and save it in a variable (for use in replacement). The block-enclosed "^\." means that we then pass the next character unless it is a period, and the asterisk that follows means that we repeat this for an arbitrary number of characters (until a period is reached). And the final "\." means that we also pass the period character that was reached.

Replace with:
\1

This means that the first (and here only) parenthesis variable created by the "Text to be replaced" expression will replace the entire substring that was passed using that expression.

I have tested this method in ARen v3.82 using all three of the filenames given in your original post, and it should work equally well for any other filenames of similar form (regardless of substring lengths).

Best regards: Ulf Ronald Andersson (aka: dlanor)


13/04-18 22:51 - edited 19/04-18 02:20
#3 : 13/04-18 23:25
Mark
Mark
Posts: 175
Reply to #2:
Very neat, I like it ....

My approach was to split the text into 3 groups, the first letter, the characters up to and including the first period, and the rest.

(^.)(.*)[.](.*)
\1\3

Mark


13/04-18 23:25
#4 : 17/04-18 22:29
Todd
Todd
Posts: 2
Reply to #2:

Thanks very much; that worked perfectly! Other than a couple of collisions I could easily fix, your method did exactly what I needed. Thanks again for saving me hours worth of work.

- Todd


17/04-18 22:29