Flip text and/or numbers between dash

A swapping-ground for Regular Expression syntax

Flip text and/or numbers between dash

Postby newworld » Thu Aug 02, 2007 11:57 pm

Thank you for wonderful program.

Most of my music files are
Song title - Artist.mp3
And I'd like to change some of them to
Artist - Song title.mp3
In other words, I'd like to swap text using dash(-) as a constant.
Can you help? Much appreciated.

Note: Sometimes there is no space before/after dash(-).
newworld
 
Posts: 4
Joined: Thu Aug 02, 2007 9:48 pm

Postby Admin » Fri Aug 03, 2007 7:26 am

There's lots of examples of this already, doing very similar stuff, both in this forum and the help file.

Try this:

Match: (.+)(\s*-\s*)(.+)
Replace: \3 - \1


This is broken down into:
(.+) - Find everything, up to....
(\s*-\s*) - ....zero or more spaces, followed by a dash, follwed by zero or more spaces
(.+) - and then deal with everything that follows it.

You then deal with the components you have extracted - and in your case you flip them.



Jim
Admin
Site Admin
 
Posts: 2351
Joined: Tue Mar 08, 2005 8:39 pm

Postby newworld » Fri Aug 03, 2007 6:34 pm

Thank you so much, Jim.
Your expression worked wonderfully.

I am so new to this regex, I didn't even know it existed until now.

You have solved a long time project of mine in a single stroke.
I'll be looking more into this regex stuff, that's for sure.

Thanks again.
newworld
 
Posts: 4
Joined: Thu Aug 02, 2007 9:48 pm

Postby newworld » Fri Aug 03, 2007 7:06 pm

Just found one problem.

Some of my music files are in another language(korean,specifically).
And new file name become:

G p - .mp3
p - .mp3
G - .mp3
- .mp3
Or file name just remains the same(no change).

These are examples I found so far.
Can there be a solution to this?
newworld
 
Posts: 4
Joined: Thu Aug 02, 2007 9:48 pm

Postby Admin » Fri Aug 03, 2007 7:29 pm

Possibly not. Most Regular Expression libraries (inlcuding the one used by BRU) do not handle Unicode.

If you need to keep the Koren names then I don't think you can use that Regular Expression.


Jim
Admin
Site Admin
 
Posts: 2351
Joined: Tue Mar 08, 2005 8:39 pm

Postby newworld » Sat Aug 04, 2007 3:52 am

Thank you anyway, Jim.
I do appreciate your help on this.

Using your expression lets me organized the way I always wanted to do.
newworld
 
Posts: 4
Joined: Thu Aug 02, 2007 9:48 pm


Return to Regular Expressions