Copy first letter of every word in a file name

A swapping-ground for Regular Expression syntax

Copy first letter of every word in a file name

Postby ThanhLoan » Fri Dec 11, 2009 8:35 pm

Hi,
I am not very knowledgeable with BRU but I manage to do alot of thing with this wonderful utility.
One thing I am still seeking for a solution :
I would like to extract the first letter of all the word in a filename and paste them to the end of the filename.
Exp : old filename : I Want To Hold Your Hand.mkv
new filename : I Want To Hold Your Hand-IWTHYH.mkv

Thank you in advance for your help.
ThanhLoan
 
Posts: 7
Joined: Fri Dec 11, 2009 8:22 pm

Re: Copy first letter of every word in a file name

Postby ThanhLoan » Wed Dec 16, 2009 8:52 pm

I dug more into RegEx and I came up with this RegEx which works for a fixed number of words in a songname.
My intial request was for adding abbreviation of songname in a karaoke filename.

Example :
my original karaoke filename :
SunFly116_12-Singer Name-Aname Bname Cname Dname Ename Fname Gname.mkv

I want to rename it to :
SunFly116_12-Singer Name-Aname Bname Cname Dname Ename Fname Gname-ABCDEFG.mkv

This is the RegEx :
(.*)(([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]* ([A-Z])[a-z]*)
Replace : \1\2-\3\4\5\6\7\8

However, this RegEx only works with a songname of 7 words exactly (Aname to Gname) and I don't know how to make it work for any number of words in the songname.

Please advise

Thank you very much for your help
ThanhLoan
 
Posts: 7
Joined: Fri Dec 11, 2009 8:22 pm

Re: Copy first letter of every word in a file name

Postby ThanhLoan » Thu Dec 17, 2009 12:19 am

and this RegEx of mine does not work with Unicode File name...

Please advise how I can match any Unicode character.

Thank you
ThanhLoan
 
Posts: 7
Joined: Fri Dec 11, 2009 8:22 pm

Re: Copy first letter of every word in a file name

Postby Stefan » Fri Dec 18, 2009 1:17 am

Hi ThanhLoan,

there is no need for double posting your issue in different threads.

> However, this RegEx only works with a songname of 7 words exactly (Aname to Gname)
> and I don't know how to make it work for any number of words in the songname.
That is not possible.
Regular expression is an pattern matching system. You have to find an common pattern to match and this is not really flexible for different patterns.
And RegEx can handle 9 backreferences only anyway, so you are limited by this with your parts of file name.

You have to use an script to say something like
"PARTS = split file name at space"
"for each part in PARTS save first capital letter to var X..."
"NewFileName = OldFileNamePart + "_" + X + "." + OldFileNameExtension"
You can use VBscript or PERL or AutoHotkey or like this... or try Den4b ReNamer which can use PascalScript and has an active forum to aid you.

> Please advise how I can match any Unicode character.
I have no glue.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions