sys_RegexFind* not found ?!
sys_RegexFind* not found ?!
Hello,
I am using TGF for a couple of years, now, to (re)tag, rename and restructure the transcoded / bought musicfiles into my personal music structure.
My scripts are doing complex things, and I rely on methods like sys_RegexFind a lot.
Recently, after updating I discovered that for the latest version, 0.89b (2015/06/30) the sys_RegexFind method returns a syntax error "Unknown identifier 'sys_RegexFind'". Since it worked in the past, I downgraded to 0.88 (the one from the download page when you use the "Download here" link). This version however returns the same error for sys_RegexFindStr.
I don't have the old version I had before the update, when all was working just fine, anymore, to see which version that was, only that it was before 0.88 I can say for sure.
Can you please take a look why these methods are not there anymore, all of a sudden?
Thanks a lot.
- Karubian
I am using TGF for a couple of years, now, to (re)tag, rename and restructure the transcoded / bought musicfiles into my personal music structure.
My scripts are doing complex things, and I rely on methods like sys_RegexFind a lot.
Recently, after updating I discovered that for the latest version, 0.89b (2015/06/30) the sys_RegexFind method returns a syntax error "Unknown identifier 'sys_RegexFind'". Since it worked in the past, I downgraded to 0.88 (the one from the download page when you use the "Download here" link). This version however returns the same error for sys_RegexFindStr.
I don't have the old version I had before the update, when all was working just fine, anymore, to see which version that was, only that it was before 0.88 I can say for sure.
Can you please take a look why these methods are not there anymore, all of a sudden?
Thanks a lot.
- Karubian
Re: sys_RegexFind* not found ?!
Some regex script functions parameters have changed, the function now is defined as
Also sys_RegexFindStr was removed but it seems it still appears in the autocomplete of the editor.
I have refreshed and uploaded the beta, you can test the default script #regex.sct and see if it works for you.
Code: Select all
function sys_RegexFind( sSource, sRegexExpr: string ): boolean;
I have refreshed and uploaded the beta, you can test the default script #regex.sct and see if it works for you.
Re: sys_RegexFind* not found ?!
The sys_RegexFind seems fine now, however...jtclipper wrote:I have refreshed and uploaded the beta, you can test the default script #regex.sct and see if it works for you.
This poses a problem for my scripts, which rely on the ability to extract the captured string from a matching regex, and do things with them.jtclipper wrote:Also sys_RegexFindStr was removed but it seems it still appears in the autocomplete of the editor.
What was the reason for removing that function?
Can you please re-add it again? It's vital for my scripts to have this functionality.
- Karubian
Re: sys_RegexFind* not found ?!
I changed the regex library a while back and this function fell through the cracks somehow, I got it back up and the beta is refreshed.
Please check to see if it works properly.
Please check to see if it works properly.
Re: sys_RegexFind* not found ?!
Yes, the two functions mentioned above are working just fine, now. Thanks a lot.
However...(there's always a "but"...)
The method sys_RegexReplace(...) seems to have lost it's former power, the last parameter is only a string now, not an array anymore. It was very powerful to have the actual replacements in an array, to specify which capture should be replaced by which replacement. Replacing everything that matches the captures with the same single string is not always a good thing.
Would it be possible to bring that former power back? Otherwise I would have to implement multiple calls to the replacement function, and that would kind of clutter the code...
However...(there's always a "but"...)
The method sys_RegexReplace(...) seems to have lost it's former power, the last parameter is only a string now, not an array anymore. It was very powerful to have the actual replacements in an array, to specify which capture should be replaced by which replacement. Replacing everything that matches the captures with the same single string is not always a good thing.
Would it be possible to bring that former power back? Otherwise I would have to implement multiple calls to the replacement function, and that would kind of clutter the code...
Re: sys_RegexFind* not found ?!
Will look in to it but can you provide me with an example (source, pattern) of the regex you use so I can do a few tests
Re: sys_RegexFind* not found ?!
Of course I canjtclipper wrote:Will look in to it but can you provide me with an example (source, pattern) of the regex you use so I can do a few tests
![Smiley :)](./images/smilies/smiley.gif)
This is one of many functions in my retag/rename script. It's using all three sys_RegexFind, sys_RegexReplace, and sys_RegexFindStr methods, and provides a good example of regex-patterns and replacement-arrays.
Code: Select all
const DISK_PATTERN = '([Cc][Dd]|[Dd][Ii][Ss][Kk]|[Dd][Ii][Ss][Cc])';
VOLUME_PATTERN = '([Vv][Oo][Ll]\.*|[Vv][Oo][Ll][Uu][Mm][Ee])';
function sanitizeAlbum(const text : string) : string;
var saneText : string;
nr : string;
begin
//sys_LogEvent('sanitizeAlbum()', 'album: "' + text + '"', 0);
if sys_RegexFind(text, VOLUME_PATTERN + '\s*\d+') then begin
// extract the disk-number...
nr := Trim(sys_RegexFindStr(text, VOLUME_PATTERN + '\s*(\d+)', 2));
//sys_LogEvent('sanitizeAlbum()', 'volume: "' + nr + '"', 0);
// unify the text...
saneText := Trim(sys_RegexReplace(text, VOLUME_PATTERN + '(\s*\d+)', [1, 'Volume ', 2, nr]));
end else if sys_RegexFind(text, DISK_PATTERN + '\s*\d+') then begin
// extract the disk-number...
nr := Trim(sys_RegexFindStr(text, DISK_PATTERN + '\s*(\d+)', 2));
//sys_LogEvent('sanitizeAlbum()', 'disc: "' + nr + '"', 0);
// unify the text...
saneText := Trim(sys_RegexReplace(text, DISK_PATTERN + '(\s*\d+)', [1, 'CD ', 2, nr]));
end else begin
// nothing to be done, so just trim it.
saneText := Trim(text);
end;
//sys_LogEvent('sanitizeAlbum()', 'sanitized album: "' + saneText + '"', 0);
result := saneText;
end;
Re: sys_RegexFind* not found ?!
Can you please also provide me an example of the source before and after the replacement, since the new library uses groups a bid differently I want to be sure this will work
Re: sys_RegexFind* not found ?!
Sorry, I forgot to add the source strings...The collection of strings below should do just fine.
In case of "Name C", the method from my previous post will of course only go for the "Volume" match and not hit on the Disk, so that's perfectly ok. Multivolume/Multidisk situations are handled in stages, not at once. ![Smiley :)](./images/smilies/smiley.gif)
Code: Select all
Name A CD 1
Name B Volume 1
Name C Vol. 1 Disk 2
Name A Disk 2
![Smiley :)](./images/smilies/smiley.gif)
Re: sys_RegexFind* not found ?!
Refreshed the beta, added the function
You will need to re-test your code against a few examples to make sure it behaves the same.
Code: Select all
sys_RegexReplaceStr
Re: sys_RegexFind* not found ?!
Sorry for never replying...problems seem to be solved, thanks a lot ![Smiley :)](./images/smilies/smiley.gif)
![Smiley :)](./images/smilies/smiley.gif)