removing various things from filenames

A swapping-ground for Regular Expression syntax

removing various things from filenames

Postby matt_t » Mon May 17, 2010 5:43 pm

Hi, new user here. Have browsed the forum but can't find an answer to these specific queries, and since all this looks like Greek to me, A) I probably wouldn't have recognized it if I'd seen it, and B) please be gentle with me! :)

How can I rename a file such as:

02-Accompagnato (Tenor). Comfort ye my people.flac

so it becomes simply

02-Comfort ye my people.flac

i.e. remove all characters up to and including the space after the dot, but leave the first 3 characters (the track number) intact?


And another one:

How to rename e.g.

15-Thou, Merab, first in birth (Recit. Saul, Merab) - My soul rejects (Air. Merab) - See, with what a scornful air - Ah, lovely youth (Air. Michal).flac

to be

15-Thou, Merab, first in birth - My soul rejects - See, with what a scornful air - Ah, lovely youth.flac

i.e. remove all brackets and their contents, and leave only one space either side of the hyphen? [I guess the space bit is done by using "Remove - D/S" in box 5.]

[I did find one thread about removing brackets, but the example related to square brackets instead of round ones, and as the expression itself used brackets it all looked totally unintelligible to a noob like me!]

Many thanks in advance!
matt_t
 
Posts: 3
Joined: Mon May 17, 2010 5:26 pm

Re: removing various things from filenames

Postby Stefan » Mon May 17, 2010 9:48 pm

Hi matt welcome!

matt_t wrote:Hi, new user here. Have browsed the forum but can't find an answer to these specific queries, and since all this looks like Greek to me, A) I probably wouldn't have recognized it if I'd seen it, and B) please be gentle with me! :)

How can I rename a file such as:

02-Accompagnato (Tenor). Comfort ye my people.flac

so it becomes simply

02-Comfort ye my people.flac

i.e. remove all characters up to and including the space after the dot, but leave the first 3 characters (the track number) intact?


Test this with some test files:

FROM:
02-Accompagnato (Tenor). Comfort ye my people.flac
TO:
02-Comfort ye my people.flac

DO:
RegEx(1)
Search: (\d\d-).+\.\s(.+)
Repla: \1\2

Explanation:
(\d\d-) means match two digits \d followed by an dash and group this for reuse (...) by \1
.+ means match one-or-more of any sign till...
\.\s means an dot followed by an space
(.+) means match one-or-more of any sign and group this for reuse (...) by \2


Then we replace with what is matched in the first (...) group by \1
and that from the second group by \2
dropping the middle part.


And another one:

How to rename e.g.

15-Thou, Merab, first in birth (Recit. Saul, Merab) - My soul rejects (Air. Merab) - See, with what a scornful air - Ah, lovely youth (Air. Michal).flac

to be

15-Thou, Merab, first in birth - My soul rejects - See, with what a scornful air - Ah, lovely youth.flac

i.e. remove all brackets and their contents, and leave only one space either side of the hyphen? [I guess the space bit is done by using "Remove - D/S" in box 5.]

[I did find one thread about removing brackets, but the example related to square brackets instead of round ones, and as the expression itself used brackets it all looked totally unintelligible to a noob like me!]

Many thanks in advance!

Test this with some test files:

FROM:
15-Thou, Merab, first in birth (Recit. Saul, Merab) - My soul rejects (Air. Merab) - See, with what a scornful air - Ah, lovely youth (Air. Michal).flac
TO:
15-Thou, Merab, first in birth - My soul rejects - See, with what a scornful air - Ah, lovely youth.flac

DO:
RegEx(1)
Search: (.+)\(.+\)(.+)\(.+\)(.+)\(.+\)
Repla: \1\2\3

Explanation:
(.+) means match one-or-more of any sign and group this for reuse (...) by \1

and now \(.+\)
\( means match an ( literary . Because ( are regex meta signs we have to escape them by an \
.+ means match one-or-more of any sign
\) means match )

Since you have three (...) brackets and their contents to remove, we copy this (.+)\(.+\) construct three times.


To remove double space the D/S seams to work :
Remove(5) [X] D/S



HTH? :D
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions