You are not logged in.
Hello!
I need help with regular expression code for this :-
The text before the following special characters in the file name [-] OR [–] OR [—] >>> Capitalize Every Word
The text after the following special characters in the file name [-] OR [–] OR [—] >>> Sentence case
For Example:
Input:
the last samurai – the way of the sword.mp3
The Result:
The Last Samurai – The way of the sword.mp3
Hope you help
Thanks!
Offline
How about a Pascal Script rule instead?
var
BaseName, Delimeter: WideString;
DelimeterPosition: Integer;
Positions: TIntegerArray;
Matches: TWideStringArray;
begin
BaseName := WideExtractBaseName(FileName);
if FindRegEx(BaseName, '\s+(-|–|—)\s+', False, Positions, Matches) > 0 then
begin
Delimeter := Matches[0];
DelimeterPosition := Positions[0];
BaseName := WideCaseCapitalize(Copy(BaseName, 1, DelimeterPosition - 1)) + Delimeter +
WideCaseSentence(Copy(BaseName, DelimeterPosition + Length(Delimeter), Length(BaseName)));
FileName := BaseName + WideExtractFileExt(FileName);
end;
end.
This script will handle all three delimiters that you mentioned: "-" (U+002D), "–" (U+2013) and "—" (U+2014).
Offline
Works Perfectly!
Thank you so much
Offline
I forget something..
If there's ( ) in the file name i want the text inside it to be sentence case also
Example:
Input:
the last samurai – the way of the sword (VERSION 01).mp3
The Result:
The Last Samurai – The way of the sword (Version 01).mp3
Can you edit the script please ?
Offline
This script will also handle the bracketed content at the end of the filename.
var
BaseName, Match: WideString;
Position: Integer;
Positions: TIntegerArray;
Matches: TWideStringArray;
begin
BaseName := WideExtractBaseName(FileName);
if FindRegEx(BaseName, '\s+(-|–|—)\s+', False, Positions, Matches) > 0 then
begin
Match := Matches[0];
Position := Positions[0];
BaseName := WideCaseCapitalize(Copy(BaseName, 1, Position - 1)) + Match +
WideCaseSentence(Copy(BaseName, Position + Length(Match), Length(BaseName)));
if FindRegEx(BaseName, '\(.*?\)\Z', False, Positions, Matches) > 0 then
begin
Match := Matches[0];
Position := Positions[0];
BaseName := Copy(BaseName, 1, Position - 1) +
WideCaseSentence(Copy(BaseName, Position, Length(BaseName)));
end;
FileName := BaseName + WideExtractFileExt(FileName);
end;
end.
Offline
Excellent!
Thanks
Offline