can i rename '1st part - 2nd part to be 2nd part - 1st part

A swapping-ground for Regular Expression syntax

can i rename '1st part - 2nd part to be 2nd part - 1st part

Postby Redheadpeter » Mon Nov 08, 2010 5:51 pm

I have lots of files which have been 'wrongly' named.

They start with a group of words, then a - (dash), then a space then more words.
I want to move the words that are before the - to be moved after it and the words after the - to go before it.

Can do?
Redheadpeter
 
Posts: 1
Joined: Mon Nov 08, 2010 5:42 pm

Re: can i rename '1st part - 2nd part to be 2nd part - 1st part

Postby Jane » Fri Nov 26, 2010 6:49 am

There are plenty of examples similar to yours; for example:
http://www.bulkrenameutility.co.uk/forum/viewtopic.php?f=3&t=700

Also, check the help file that is part of the Bulk Rename utility - look under the section:
Regular Expressions - A Working Example
where they show how to swap things around.

Give it a try and see how you do.

Jane
Jane
 
Posts: 24
Joined: Sat Aug 05, 2006 1:20 am

Re: can i rename '1st part - 2nd part to be 2nd part - 1st part

Postby DefAnt » Thu Dec 30, 2010 4:37 pm

Try using this in RegEx box.

Match:
(\d*)(- )(\d*)
Replace:
\3\2\1

(\d*) copies all digits until the next character that isn't a letter and assigns it to it's respective grouping, 1 and 3.
(- ) takes the dash and space and puts it into Grouping 2.

The 3rd group of digits moves to 1st position, followed by 2nd grouping with the dash and space, followed by the 1st group of digits moved to the 3rd position.

However, upon rereading your post you say "words" not "digits" so you'd use (.*) instead of (\d*)

The thread Jane points you to also will help you out in this task. It helped me remember that .* which is what I was about to look for haha.

Good luck and nice job finding the thread and help section Jane.
DefAnt
 
Posts: 16
Joined: Tue Sep 14, 2010 7:28 pm
Location: New Jersey, USA


Return to Regular Expressions