sys_RegexFind* not found ?!

Use this forum for everything concerning script usage
Post Reply
Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

sys_RegexFind* not found ?!

Post 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

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: sys_RegexFind* not found ?!

Post 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.

Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

Re: sys_RegexFind* not found ?!

Post 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

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: sys_RegexFind* not found ?!

Post 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.

Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

Re: sys_RegexFind* not found ?!

Post 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...

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: sys_RegexFind* not found ?!

Post 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

Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

Re: sys_RegexFind* not found ?!

Post 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;

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: sys_RegexFind* not found ?!

Post 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

Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

Re: sys_RegexFind* not found ?!

Post 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. :)

User avatar
jtclipper
Administrator
Administrator
Posts: 768
Joined: Tue Aug 10, 2010 12:04 pm

Re: sys_RegexFind* not found ?!

Post 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.

Karubian
Newbie
Newbie
Posts: 8
Joined: Fri Sep 11, 2015 5:44 am

Re: sys_RegexFind* not found ?!

Post by Karubian »

Sorry for never replying...problems seem to be solved, thanks a lot :)

Post Reply