#11 2008-03-09 22:05

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,284

Re: ReplaceRegEx and MatchesRegEx functions in PascalScript

Done, DialogYesNo and WideDialogYesNo are added smile

ReNamerBeta.zip

Regarding custom dialogs... Bad idea, because customizable dialogs will require more type definitions for buttons, message type, etc. Also, Delphi and PascalScript do not allow variable parameters list, so your idea will not work.

Offline

#12 2008-03-09 23:29

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: ReplaceRegEx and MatchesRegEx functions in PascalScript

THANKS!
You're quick as a lightning!


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#13 2009-07-25 13:01

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,149

Re: ReplaceRegEx and MatchesRegEx functions in PascalScript

den4b wrote:

I was thinking of the best way to add this functionality, and here is what I came too...

function SubMatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TStringsArray;

This functions is very similar to MatchesRegEx, but instead of returning full expression matches it will return an array of sub-expression matches for the first full expression match.[...]

Many thanks for suggestion and implementation big_smile

Only now i had the need to use this and after some tests it works great.

var
    NamePart: TStringsArray;

begin
    NamePart := SubMatchesRegEx(FileName, '(.+)( - )(.)(.+)(\..+)',False)
    FileName  := WideCaseCapitalize(NamePart[0]) + NamePart[1];
    FileName  := FileName + WideUpperCase(NamePart[2]) + WideLowerCase(NamePart[3]);
    FileName  := FileName + WideUpperCase(NamePart[4]);
end.

Here is the same code with explanations:

// F.ex.: from "meat loaf - bat out of hell.mp3"   to   "Meat Loaf - Bat out of hell.MP3"

// SubMatch RegEx's:
// NamePart[0]    (.+)      One or more of ANY char                          = meat loaf
// NamePart[1]    ( - )     BlankDashBlank                                    =  -
// NamePart[2]    (.)        One piece of ANY char                            = b
// NamePart[3]    (.+)      One or more of ANY char                           = at out of hell
// NamePart[4]    (\..+)    dot itself and One or more of ANY char            = .mp3


 var
    NamePart: TStringsArray;

begin
          //SubMatchesRegEx(const Input, Find: WideString; const CaseSensitive: Boolean): TStringsArray;
    NamePart   := SubMatchesRegEx(FileName, '(.+)( - )(.)(.+)(\..+)',False)
   //ShowMessage('Debug: #'+NamePart[0]+'#'+NamePart[1]+'#'+NamePart[2]+'#'+NamePart[3]+'#'+NamePart[4]+'#');
    FileName := WideCaseCapitalize(NamePart[0]) + NamePart[1];
    FileName := FileName + WideUpperCase(NamePart[2]) + WideLowerCase(NamePart[3]);
    FileName := FileName + WideUpperCase(NamePart[4]);
end.

THX  :thumpsup:


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#14 2009-07-26 18:18

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: ReplaceRegEx and MatchesRegEx functions in PascalScript

Hi, Stefan!

You might be interested in a bit more general script for changing case of regex's capturing groups.
I've written it thanks to the SubMatchesRegEx function.
You may find it here.


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

Board footer

Powered by FluxBB