Move entire name to end of of file excluding last word.

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Move entire name to end of of file excluding last word.

Postby Cardboard231 » Thu Apr 16, 2020 12:19 pm

I'm having trouble communication what I'm trying to do in the title. So I'll just give an example.

E.g.
The File Name starts off as:
R. M. Ballantyne
And Ends ups as:
Ballantyne, B. M.

I've already added a coma to the end of each name. Once I know how to do this I will add a space at the start before doing it.

Thank you in advanced. And thank you to the developers, I've been using this program for years for endless different things.
Cardboard231
 
Posts: 2
Joined: Thu Apr 16, 2020 12:11 pm

Re: Move entire name to end of of file excluding last word.

Postby RegexNinja » Thu Apr 16, 2020 2:06 pm

Without seeing OrigNames, this is only a guess..
If you've already added commas (unlike the example given) and B. is a typo:

#1Regex Match/Replace:
^(.*)([A-Z]\. [A-Z]\.) ([A-Z].*?,)(.*)$
\1\3 \2\4

Results:
R. M. Ballantyne, --------------> Ballantyne, R. M.
Begin R. M. Ballantyne, End --> Begin Ballantyne, R. M. End
Begin R. M. Ballantyne End ---> no effect (no comma in name-string)
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Move entire name to end of of file excluding last word.

Postby Cardboard231 » Fri Apr 17, 2020 5:36 am

Thank you sir. You are a wizard. I apologize for my mistakes however your assumptions were correct. I couldn't tell you what 1 part of that means however it worked perfectly.

Is there somewhere I can learn what it means? So I don't have to ask again.
Cardboard231
 
Posts: 2
Joined: Thu Apr 16, 2020 12:11 pm

Re: Move entire name to end of of file excluding last word.

Postby RegexNinja » Fri Apr 17, 2020 2:41 pm

There's a new manual at http://www.bulkrenameutility.co.uk/foru ... =12&t=4743 & it covers regex too.
There's also a regex post at http://www.bulkrenameutility.co.uk/foru ... p?f=3&t=96.
I think that post includes links to places for learning regex..

I'll cover this one the best I can. Consider it just a primer:
The regex match-box works by (Grouping) text that you wanna keep.
Anything that's been (Grouped) in the match-box can be represented by \# in the replacement-box.

The 1st-set of parenthesis in the match-box is Group1, the 2nd-set is Group2, etc..
If theres some filename-text you dont want, there's no need to (Group-it) within parenthesis.

The replacement-box is where you can re-order groups, if desired like: \4\3\2\1 (to reverse the groups).
Its also where you include your additions to the groups like: \1\2_\3\4abc--\1\1xyz
Replacements are the easy part, but matching can be frustrating when starting out.

One of the tricky things to matching, is that regex has few special-chars like: [](){}.?*^$.
If you have those in a filename, they must be matched with a leading backslash like: \[ or \] etc.
There's not alot them, so once you know what they are, you're good to go.

Character-sets are specified like: [A-Z] for 1-Uppercase-Letter, or like: [a-c] for a, b, or c.
You can also spec them as: [A-Z]{2,4} for at least 2-Uppercases, but not more than four.
But almost everyone uses: [A-Z]+ for 1-or-more.. There's also [A-Z]* for 0-or-more.

. is a char-set all by itself, it means any 1-character, so...
(.*)XX matches everything until the last-occurence of XX.
(.*?)XX matches everything until the 1st-occurence of XX.

So with your example:
^(.*)([A-Z]\. [A-Z]\.) ([A-Z].*?,)(.*)$
\1\3 \2\4

Group1: (.*)
Matches anything until the last-occurence of what follows in the match-box (Group2) etc.
Since * means 0-or-More, this group can match nothing (desired in case name starts like: R. M.)

Group2: ([A-Z]\. [A-Z]\.)
Matches UpperCase. Uppercase.

Group3: ([A-Z].*?,)
Matches Uppercase anything until the 1st-occurence of comma

Group4: (.*)
Matches anything until the end of filename..
Like Group1, it can match nothing (in case Group3 already matched end of filename).

The leading ^ means to start matching at the 1st-character in filename, and $ means end-of-filename.
You dont always need them, but its a very good practice.. The replacement just re-orders the groups & adds a space.
Cheers.
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to BRU Support