I want to do: sys_RegexFind( mystring, ' \(Disc (.?)\)' )
and then later use $1 => which should equal the match of (.?)
Or somehow get the value of the item I matched and use it later.
-----------
What I am trying to do is the following: I have a large # of flac files that have an album field like "Some Album (Disc X)". I want to write a script which finds (Disc X), deletes it from the album field and adds DISCNUM X as one of the custom fields in the tag. The modification part of the Album tag is straightforward as is adding a new tag (DISCNUM) however I need to get the value of X from the regex so I can use it when creating the new field.
Using regexpr and () to group and extract substrings
Re: Using regexpr and () to group and extract substrings
I will add another system function to extract the match of the regex find and return it in the next beta (3).
If you are in a hurry this can also be done by using Pos() and some manuall processing of the data.
If you are in a hurry this can also be done by using Pos() and some manuall processing of the data.
Dimitris
Re: Using regexpr and () to group and extract substrings
Just as an aside, I find this very handy when working with regex. I don't do enough to keep it straight in my head.
http://msdn.microsoft.com/en-us/library/az24scfc.aspx
http://msdn.microsoft.com/en-us/library/az24scfc.aspx
Re: Using regexpr and () to group and extract substrings
Beta 3 has a new regex function
Example
Code: Select all
function sys_RegexFindStr( sSource, sRegexExpr: string; iIdx: integer ): string;
Code: Select all
program test;
var
sTmp: string;
begin
sTmp := '172.16.225.101';
ShowMessage( sys_RegexFindStr( sTmp, '(\d+)\.(\d+)\.(\d+)\.(\d+)', 4 ) ); //<-- will return 101
end.
Dimitris
Re: Using regexpr and () to group and extract substrings
Worked like a charm. Thanks for your fast response! Another question I have however is I need to set the DISCNUMBER field (and probably DISCTOTAL as well). Is there any way to do this?
I should mention I need to set DISC related information for FLAC and MP3
I should mention I need to set DISC related information for FLAC and MP3
Last edited by danyal711 on Fri Oct 01, 2010 7:07 am, edited 1 time in total.
Re: Using regexpr and () to group and extract substrings
The basic idea is as follows:
The question is which hardware/software player will you use because some may or may not use that info.
Code: Select all
program test;
begin
if not tg_Init then exit;
repeat
tg_LoadFile;
gTag.ExtraFieldSet( 'DISCNUMBER', '3' )
gTag.SaveToFile( 0, false, '', false);
until not tg_Skip;
end.
Dimitris
Re: Using regexpr and () to group and extract substrings
Dimitris, how to replace all commas to dots in string?
"a, b, c, d" replace to "a. b. c. g"
"a, b, c, d" replace to "a. b. c. g"
Re: Using regexpr and () to group and extract substrings
You can use the following method
Code: Select all
program test;
var
sTmp: string;
begin
sTmp := '10.10.10.50';
sTmp := AnsiReplacetext( sTmp, '.', ',' );
ShowMessage( stmp );
end.
Dimitris