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.

4 Pages V  « < 2 3 4  
Closed TopicStart new topic
> Regular Expressions, Examples of actions with Regular Expressions
DetlevD
post Aug 1 2011, 05:03
Post #46


Member


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



Convert from RFC822/1123 Date string to ISO-8601 Date string.

Examples:
RFC822/RFC 1123 ==> ISO-8601
1 Feb 2009 ==> 2009-02-01
30 Sep 2010 ==> 2010-09-30

$replace($regexp($right('0'%YEAR%,11),
'(\d{1,2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{2,4})','$3-$2-$1'),
'Jan','01','Feb','02','Mar','03','Apr','04','May','05','Jun','06',
'Jul','07','Aug','08','Sep','09','Oct','10','Nov','11','Dec','12')


See also:
http://www.w3.org/Protocols/rfc822/
http://www.freesoft.org/CIE/RFC/1123/99.htm

DD.20110801.0623.CEST


Example:
1 Feb 2009 HH:MM ==> 2009-02-01 HH:MM

$replace($regexp($right('0'$cutRight(%YEAR%,6),11),
'(\d{1,2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{2,4})','$3-$2-$1'),
'Jan','01','Feb','02','Mar','03','Apr','04','May','05','Jun','06',
'Jul','07','Aug','08','Sep','09','Oct','10','Nov','11','Dec','12')$right(%YEAR%,6)


DD.20140310.2236.CET

This post has been edited by DetlevD: Mar 10 2014, 22:36


--------------------
* 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
DetlevD
post Aug 24 2011, 15:55
Post #47


Member


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



How to copy a list of artists and their roles ...
... from tag-field COMMENT
... to tag-field INVOLVEDPEOPLE


Example 1
From: COMMENT
Person1:Role1
Person2:Role2
Person3:Role3

To: INVOLVEDPEOPLE
Role1:Person1;Role2:Person2;Role3:Person3;

Action: Format value
Field: INVOLVEDPEOPLE
Formatstring:
$regexp(%COMMENT%$char(13),'(.+?):(.+?)[\r\n]+','$2:$1;')


Example 2
From: COMMENT
Person1:Role1
Person2: Role2a,Role2b
Person3 : Role3a, Role3b
Person4: Role4a & Role4b, Role4c

To: INVOLVEDPEOPLE
Role1:Person1;Role2a,Role2b:Person2;Role3a,Role3b:Person3;Role4a & Role4b,Role4c:Person4;

Action: Format value
Field: INVOLVEDPEOPLE
Formatstring:
$regexp($regexp(%COMMENT%$char(13),'(.+?)\s*:\s*(.+?)[\r\n]+','$2:$1;'),'\s*,\s*',',')

DD.20110824.1757.CEST

This post has been edited by DetlevD: Aug 24 2011, 16:55


--------------------
* 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
pone
post Aug 24 2011, 16:29
Post #48


Member


Group: Full Members
Posts: 1688
Joined: 15-March 09
From: Germany
Member No.: 9103
Mp3tag Version: 2.59b



ZITAT(DetlevD @ Aug 24 2011, 16:55) *
$regexp(%COMMENT%$char(13),'(.+?) :( .+?)[\r\n]+','$2:$1;')
...
$regexp($regexp(%COMMENT%$char(13),'(.+?)\s*:\s*(.+?)[\r\n]+','$2:$1;'),'\s*,\s*',',')


What is $char(13) ? And why is it needed here?

This post has been edited by pone: Aug 24 2011, 16:30
Go to the top of the page
 
+Quote Post
DetlevD
post Aug 24 2011, 16:48
Post #49


Member


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



QUOTE (pone @ Aug 24 2011, 17:29) *
What is $char(13) ? And why is it needed here?

$char(13) is the "CarriageReturn" control character.
It is appended here on the fly to the COMMENT string as a helper, just to make sure, that there is at least one "CarriageReturn" character at the end of the COMMENT string, in order to let the RegExp work correctly, even for the case, when the original COMMENT string has no trailing CarriageReturn/LineFeed sequence.

DD.20110824.1750.CEST


--------------------
* 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
naisanza
post Feb 8 2013, 00:55
Post #50


Member


Group: Members
Posts: 1
Joined: 18-December 07
Member No.: 6138
Mp3tag Version: 2.39



If you want to add TEXT to the existing tag:

Regular expression: (.*)
Replace with: TEXT \1 \0

I found that if you don't put in the \0 at the end it will repeat TEXT twice. For example:

Title: Texty text
Becomes: TEXT Texty textTEXT


I'm using v2.48. This might of been fixed in the later versions, but it's the version I've been using and some things I refuse to update to a newer version since I've never had any other issues with it except for this one bit of annoyance.
Go to the top of the page
 
+Quote Post
RevRagnarok
post Apr 5 2013, 10:41
Post #51


Member


Group: Full Members
Posts: 15
Joined: 18-November 04
Member No.: 1325
Mp3tag Version: 2.26



QUOTE (naisanza @ Feb 7 2013, 18:55) *
Regular expression: (.*)
Replace with: TEXT \1 \0

I found that if you don't put in the \0 at the end it will repeat TEXT twice. For example:

Title: Texty text
Becomes: TEXT Texty textTEXT


What seems to be happening is the "end of line" is being matched a second time for some reason.

Using 2.48, I duplicated your bug but also tweaked the RegEx to work properly.

Regular expression: ^(.*)$
Replace with: TEXT $1

That explicitly tells the engine not to include the newline in the match.
Go to the top of the page
 
+Quote Post
dano
post Apr 5 2013, 13:39
Post #52


Moderator


Group: Moderators
Posts: 5688
Joined: 4-September 03
From: Germany
Member No.: 201
Mp3tag Version: 2.65



It's not a bug.
It happens because global matching is activated by default.
That means the engine tries to match the regex pattern as many times as possible.

With (.*) the whole text is matched at first. Then the engine stands at the end of the text. And it tries to match the pattern again.
And it succeeds because .* also matches "nothing".


But I'd prefer a simple "Format value" action is for this task anyway.


--------------------
Go to the top of the page
 
+Quote Post
Luctus
post Mar 10 2014, 18:36
Post #53


Member


Group: Members
Posts: 3
Joined: 27-November 11
Member No.: 15635
Mp3tag Version: 2.58



QUOTE (DetlevD @ Aug 1 2011, 06:03) *
Convert from RFC822/1123 Date string to ISO-8601 Date string.

Examples:
RFC822/RFC 1123 ==> ISO-8601
1 Feb 2009 ==> 2009-02-01
30 Sep 2010 ==> 2010-09-30

$replace($regexp($right('0'%YEAR%,11),'(\d{1,2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{2,4})','$3-$2-$1'),'Jan','01','Feb','02','Mar','03','Apr','04','May','05','Jun','06','Jul','07','Aug','08','Sep','09','Oct','10','Nov','11','Dec','12')

See also:
http://www.w3.org/Protocols/rfc822/
http://www.freesoft.org/CIE/RFC/1123/99.htm

DD.20110801.0623.CEST


Can you help me to convert 1 Feb 2009 HH:MM to 2009-02-01 HH:MM
Go to the top of the page
 
+Quote Post
DetlevD
post Mar 10 2014, 22:38
Post #54


Member


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



QUOTE (Luctus @ Mar 10 2014, 18:36) *
Can you help me to convert 1 Feb 2009 HH:MM to 2009-02-01 HH:MM

Read there ...
http://forums.mp3tag.de/index.php?showtopi...ost&p=57253

DD.20140310.2238.CET


--------------------
* 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

4 Pages V  « < 2 3 4
Closed 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: 23rd October 2014 - 22:15