IPB

Welcome Guest ( Log In | Register )

> Notice!

Please take a minute to check our Frequently Asked Questions. Use Search to reveal possible related topics.

Also make sure you've read the Forum Guidelines before posting in this forum.

2 Pages V  < 1 2  
Reply to this topicStart new topic
> Another quick question (RE: copying portions of a tag field)
ohrenkino
post May 14 2012, 21:51
Post #16


Member


Group: Full Members
Posts: 4389
Joined: 9-December 09
From: Norddeutschland / Northern Germany
Member No.: 11458
Mp3tag Version: 2.61d



ZITAT(ico4498 @ May 14 2012, 21:35) *
...that seems to describe the album tag in two subsets. everything before the final space & everything after. ..

Yes, this is the non-gready approach of the parser.

So, if you tried to do it in several steps instead of just one, you might be closer:
Create actions that do the following:

First copy everything from ALBUM to LABEL
Then replace with regular expressions or the tag-tag-converter until there is only the number of words left that you want e.g. with a filter like
NOT %label% MATCHES "^.* .*$"


--------------------
42 - wie war die Frage / what was the question / comment était la question
Go to the top of the page
 
+Quote Post
ico4498
post May 15 2012, 17:34
Post #17


Member


Group: Members
Posts: 4
Joined: 31-March 10
Member No.: 12176
Mp3tag Version: 2.46a



QUOTE (ohrenkino @ May 14 2012, 14:51) *
Yes, this is the non-gready approach of the parser.

So, if you tried to do it in several steps instead of just one, you might be closer:
Create actions that do the following:

First copy everything from ALBUM to LABEL
Then replace with regular expressions or the tag-tag-converter until there is only the number of words left that you want e.g. with a filter like
NOT %label% MATCHES "^.* .*$"


thanks ohrenkino! i'll try that.
Go to the top of the page
 
+Quote Post
DetlevD
post May 16 2012, 09:43
Post #18


Member


Group: Full Members
Posts: 4801
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.61d



QUOTE (ico4498 @ May 12 2012, 22:25) *
... my album tag looks like "word1 word2 word3 wordn". i'd like to write the first 2 or 3 words to a new field "label", leaving the album field as is. ...

QUOTE (ico4498 @ May 14 2012, 21:35) *
i tried;
$regexp(%album%,^(.+)\s(.+)$,$1)
that seems to describe the album tag in two subsets. everything before the final space & everything after. thus in the album tag "Firehouse '86 - K. Tubby" $1 would produce "Firehouse '86 - K." & $2 "Tubby".
i'd like to describe above album as;
$1 = Firehouse
$2 = '86
$3 = -
$4 = K.
$5 = Tubby
back to the drawing board! thoughts & comments welcome.

Regarding the usage of regular espressions in Mp3tag it might help to think of a "word" as a sequence of any one character "." up to many characters ".+" resp. ".+?", delimited by the left edge of the character string "^", or by space character around the word "\s", or by the right edge of the string "$".

Note:
There is a difference between ".+" and ".+?" resp. ".*" and ".*?".
".+" is a greedy pattern, ".+?" is a non-greedy pattern.
By default, pattern matching is greedy, which means that the matcher returns the longest match possible.
For example, applying the pattern "A.*c" to "AbcAbcA" matches "AbcAbc" rather than the first shorter "Abc".
To do non-greedy matching, a question mark must be added to the quantifier.
For example, the pattern "A.*?c" will find the shortest match possible, that is the first "Abc".

In Mp3tag it looks like ...
$regexp('AbcAbcA','^(A.+c).*$','$1')
==> Result $1 = 'AbcAbc'
$regexp('AbcAbcA','^(A.+?c).*$','$1')
==> Result $1 = 'Abc'

Your example "word1 word2 word3 wordn" can be coded into regex language ...
"^.+?\s.+?\s.+?\s.+$".

In Mp3tag it looks like ...
$regexp('word1 word2 word3 word4 word5','^(.+?)\s(.+?)\s(.+?)\s(.+)$','$1 - $2 - $3 # $4')
==> Result $1 = 'word1'
==> Result $2 = 'word2'
==> Result $3 = 'word3'
==> Result $4 = 'word4 word5'
==> Result = 'word1 - word2 - word3 # word 4 word 5'

You can group parts of the expression by surrounding round brackets and refer to each group by a numbered placeholder $n.


Your example "Firehouse '86 - K. Tubby" looks like a two-parted string, delimited by the character sequence " - ", with the meaning of "ALBUM - PRODUCER" or "ALBUM - ARTIST".

In Mp3tag it can be written as ...
$regexp('Firehouse 1986 - King Tubby','^(.+?)\s-\s(.+?)$','"$2" is the producer of "$1"')
==> Result $1 = 'Firehouse 1986'
==> Result $2 = 'King Tubby'
==> Result = '"King Tubby" is the producer of "Firehouse 1986"'


Assumingly the character string "Firehouse 1986 - King Tubby" is stored in the tag-field COMMENT, and the first part "Firehouse 1986" should be stored into the tag-field ALBUM, and the second part "King Tubby" should be stored into the tag-field "ARTIST", leaving the tag-field COMMENT as is, then the process using Mp3tag actions can be as following ...

Action: Format value
Field: ALBUM
Formatstring: $regexp(%COMMENT%,'^(.+?)\s-\s.+?$','$1')
==> Result $1 = 'Firehouse 1986'

Action: Format value
Field: ARTIST
Formatstring: $regexp(%COMMENT%,'^.+?\s-\s(.+?)$','$1')
==> Result $1 = 'King Tubby'

DD.20120516.1050.CEST

This post has been edited by DetlevD: May 16 2012, 09:50


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
ico4498
post May 18 2012, 20:50
Post #19


Member


Group: Members
Posts: 4
Joined: 31-March 10
Member No.: 12176
Mp3tag Version: 2.46a



thanks ever so much DetlevD! your reply adds a lot of great information.

may take me a minute to digest it all but i'm very grateful!
Go to the top of the page
 
+Quote Post

2 Pages V  < 1 2
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 28th July 2014 - 17:25