Page 1 of 1

sys_RegexFind* not found ?!

Posted: Fri Sep 11, 2015 6:27 am
by Karubian
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

Re: sys_RegexFind* not found ?!

Posted: Fri Sep 11, 2015 9:06 am
by jtclipper
Some regex script functions parameters have changed, the function now is defined as

Code: Select all

function sys_RegexFind( sSource, sRegexExpr: string ): boolean;
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.

Re: sys_RegexFind* not found ?!

Posted: Sun Sep 13, 2015 10:24 pm
by Karubian
jtclipper wrote:I have refreshed and uploaded the beta, you can test the default script #regex.sct and see if it works for you.
The sys_RegexFind seems fine now, however...
jtclipper wrote:Also sys_RegexFindStr was removed but it seems it still appears in the autocomplete of the editor.
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.
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 ?!

Posted: Mon Sep 14, 2015 10:07 am
by jtclipper
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.

Re: sys_RegexFind* not found ?!

Posted: Tue Sep 15, 2015 5:42 am
by Karubian
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...

Re: sys_RegexFind* not found ?!

Posted: Tue Sep 15, 2015 11:41 am
by jtclipper
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 ?!

Posted: Tue Sep 15, 2015 9:37 pm
by Karubian
jtclipper 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
Of course I can :)

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 ?!

Posted: Wed Sep 16, 2015 9:16 am
by jtclipper
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 ?!

Posted: Wed Sep 16, 2015 5:05 pm
by Karubian
Sorry, I forgot to add the source strings...The collection of strings below should do just fine.

Code: Select all

Name A CD 1
Name B Volume 1
Name C Vol. 1 Disk 2
Name A Disk 2
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. :)

Re: sys_RegexFind* not found ?!

Posted: Thu Sep 17, 2015 11:08 am
by jtclipper
Refreshed the beta, added the function

Code: Select all

sys_RegexReplaceStr
You will need to re-test your code against a few examples to make sure it behaves the same.

Re: sys_RegexFind* not found ?!

Posted: Tue Mar 13, 2018 10:40 am
by Karubian
Sorry for never replying...problems seem to be solved, thanks a lot :)