Rename to match username

A swapping-ground for Regular Expression syntax

Rename to match username

Postby whyze » Tue Oct 28, 2014 11:41 pm

My apologies if this one has been covered, I'm not sure how to even properly search for this exact thing..

Here's what I have:

John Doe.jpg

Here's what I need


Filenames are full names (first and last) with a space between. I need them converted to lastname_firstinitial

Any help?

Posts: 1
Joined: Tue Oct 28, 2014 11:35 pm

Keep first sign initial name swap words exchange reorder

Postby Stefan » Wed Oct 29, 2014 7:58 am

Jane Dog.png
John Doe.jpg


RULE for two word file names:
Take first sign from first word, delete first word and space, add underscore and first sign at the very end after the second word


Match: (.)(.+? )(.+)
Repla: \3_\1

in conjunction with
Case(4) [Lower]

- - -

BUT this will convert e.g.
Carolyn Elizabet Walker.jpg
Martin Fisher Miller.txt
Sarah Maria Campbell.jpg
elizabet walker_c.jpg
fisher miller_m.txt
maria campbell_s.jpg

Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Rename to match username

Postby bgdan » Fri Nov 14, 2014 3:28 pm

Hello and sorry to hijack this thread. I have a kind of similar situation and that's why I post here.

So I need to rename:
123456ABCDE123FGH 20141114 Smith, John Lewis
123456ABCDE123FGH 20120203 Mark von Smith, John Lewis
123456ABCDE123FGH 20100109 McDonalds, John M


123456ABCDE123FGH 20141114 SmithJ
123456ABCDE123FGH 20120203 MarkvonSmithJ
123456ABCDE123FGH 20100109 McDonaldsJ

The "123456ABCDE123FGH" text never changes, it is followed by a space and the date "20141114" (this changes from one file name to another), another space ,"LastName", comma+space, and "First name"
I want the everything until the name to remain unchanged, and the name transformed from "Smith, John Lewis" to "SmithJ".
Meaning I need to remove the comma+space characters and crop the FirstName into just the 1st Letter from the FirstName.

Sometimes the Last Name has spaces (see 2nd example, Mark von Smith), I'm not sure if this makes any difference.

I tried to match using Regex like this:
Match:(123456ABCDE123FGH )(........)( )(.+)(, )(.+)
But I'm lost on how to replace it. I'm not even sure I matched correctly.

Thank you for the help!
Posts: 1
Joined: Fri Nov 14, 2014 2:48 pm

Return to Regular Expressions