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.
![]() ![]() |
Oct 16 2003, 19:47
Post
#1
|
|
![]() Developer Group: Admin Posts: 7621 Joined: 12-December 01 From: Germany, Dresden Member No.: 203 Mp3tag Version: 2.55a |
This thread collects some useful regular expressions.
If you created a regular expression which solves a common task, please post it here and give a short description what it is supposed to do. These regular expressions can be used with the action type Replace with regular expression. Please look at FAQ: How do I create a new action? to learn more about actions in Mp3tag. -> If you have problems with a regular expression, please open a separate topic. -------------------- |
|
|
|
Oct 16 2003, 19:52
Post
#2
|
|
![]() Developer Group: Admin Posts: 7621 Joined: 12-December 01 From: Germany, Dresden Member No.: 203 Mp3tag Version: 2.55a |
-------------------- |
|
|
|
Oct 16 2003, 20:42
Post
#3
|
|
|
Member Group: Full Members Posts: 12 Joined: 6-October 03 From: Brüssel Member No.: 485 |
Regular expression: ^\s*[0-9]+\s*-\s*
Replace with: This one will remove the track-number (if followed by a dash) and white space at the beginning of a string (for instance 01 - Come Together will become Come Together) Regular expression: ^\s*[0-9]+\s+ Replace with: This one will remove the track-number if followed by a white space (for instance 01 Come Together will become Come Together) This post has been edited by dano: Jun 19 2011, 19:19
Reason for edit: fixed the RE
|
|
|
|
Dec 4 2003, 20:05
Post
#4
|
|
|
Member Group: Full Members Posts: 12 Joined: 6-October 03 From: Brüssel Member No.: 485 |
Here is another one.
I don't think it will be useful as such to a lot of people, but with REGEXP, examples are never too many My files were tagged as such: name of the artist.2003AL-name of the album (the 2003AL meaning: released in 2003, Album, Live, but it could be 1977A, or 1995IR) Weird, I know I wanted to change that to a simpler 2003-name of the album Here is what I did: Regular expression: .*\.([0-9]*).*-(.+) Replace with: $1-$2 |
|
|
|
Apr 11 2004, 20:50
Post
#5
|
|
|
Member Group: Members Posts: 1 Joined: 11-April 04 Member No.: 866 |
This regular expression fixes tracknumbers from iTunes in the [track]/[numtracks] format (like 3/12).
Regex: CODE ^(\d+)/\d+ Replace with: CODE $1 This can be applied to every file and it will only correct ones that have the / in them. Good luck! According to RevRagnarok's suggestions below, I've made the expression less greedy. This post has been edited by dano: Sep 3 2006, 17:30 |
|
|
|
May 30 2004, 21:20
Post
#6
|
|
|
Member Group: Full Members Posts: 12 Joined: 6-October 03 From: Brüssel Member No.: 485 |
Another one, that switches first and last names (for instance, Jacques Brel will become Brel, Jacques):
Regular Expression: ^(.+)\s(.+)$ Replace with: $2, $1 |
|
|
|
Jul 14 2004, 10:27
Post
#7
|
|
|
Member Group: Full Members Posts: 22 Joined: 14-July 04 Member No.: 1041 Mp3tag Version: 2.37h |
Used to use this basic regexp :
Applied on TRACK, find ^(\d)$ and replace by 0$1 It adds a leading 0 to the track number. I was thinking about enhancing it to apply it only to 1-digit numbers... when I discovered Ctrl+K Cheers, MLL According to RevRagnarok's suggestions below, I've made the expression less greedy This post has been edited by Florian: Nov 18 2004, 14:31 |
|
|
|
Jul 31 2004, 23:34
Post
#8
|
|
|
Member Group: Members Posts: 3 Joined: 16-July 04 Member No.: 1045 |
If you have a filename:
Edit: Topic merged by moderator. This post has been edited by Sebastian_Mares: Aug 1 2004, 08:53 |
|
|
|
Nov 18 2004, 12:23
Post
#9
|
|
|
Member Group: Full Members Posts: 15 Joined: 18-November 04 Member No.: 1325 Mp3tag Version: 2.26 |
I've noticed a lot of these RegExs 'go overboard' in their matching. A key to good expressions are limiting (1) the false matches and (2) the how long the engine needs to analyze the string.
For example, my two favorite expressions I have posted here are both above on this page. However, they have very greedy matchers that can easily result in lost data. phoenixdarkdirk's - why NOT limit the track 'numbers' to digits with \d+ ? mll's - really went overboard when a simple ^(\d)$ would've done it. I highly recommend this book if you are serious about using REs. Of course, I recommend trying to find it at a technical library, because if you look it over a little you may realize you were just kidding and save yourself the money. Of course, when we are using them on a handful of MP3 files, it's no big deal. Edit 5 Apr 2013 - After over eight years, fixed the URL to my blog. This post has been edited by RevRagnarok: Apr 5 2013, 10:36 |
|
|
|
Nov 18 2004, 14:34
Post
#10
|
|
![]() Developer Group: Admin Posts: 7621 Joined: 12-December 01 From: Germany, Dresden Member No.: 203 Mp3tag Version: 2.55a |
RevRagnarok,
QUOTE (RevRagnarok @ Nov 18 2004, 01:23 PM) I've noticed a lot of these RegExs 'go overboard' in their matching. A key to good expressions are limiting (1) the false matches and (2) the how long the engine needs to analyze the string. Thanks a lot for your suggestions. I've changed the expressions you've mentioned to be less greedy. Best regards, ~ Florian -------------------- |
|
|
|
Mar 29 2005, 22:22
Post
#11
|
|
![]() Member Group: Full Members Posts: 383 Joined: 9-August 04 From: Germany Member No.: 1114 Mp3tag Version: 2.49 |
This RegEx will convert abbreviations composed of single chars and points between (and/or behind it) to uppercase.
Single chars without points around remains lowercase, except if a "-"char and a space is before it. (Example: "Songname - A text") CODE RegEx: ( |\.|^)(\w)(?= |\.|$) andReplace with: $1$upper($2) CODE RegEx: ([^-])( \u ) Replace with: $1$lower($2) Example: CODE a.b a Reg.eX in p.o.d p. diidi e.t. - a bad a.i ==> A.B a Reg.eX in P.O.D P. diidi E.T. - A bad A.I Both regular expressions should be executed one after another Use CODE RegEx: ( \u ) instead of second RegEx to have chars after " - " lowercase too. (Example: "Songname - a text")Replace with: $lower($1) Regards nickless Edit: removed some unnecessary characters from RegEx This post has been edited by nickless: Jul 30 2005, 15:42 -------------------- |
|
|
|
Oct 15 2005, 02:01
Post
#12
|
|
|
Member Group: Members Posts: 3 Joined: 16-July 04 Member No.: 1045 |
Title Tag Conversion
This 2-step action does: 1. set Title tag to Filename 2. convert titles using, e.g.: 01 - Track Name to 01. Track Name First step: Format Value Field: TITLE Formatstring: %_FILENAME% Second step: Set a new Replace with Regular Expression action Field: TITLE Regular expression: ^([0-9]+)\s*-\s* Replace matches with: $1. $2 I use the first format for all file names, but my iRiver displays the title tag, which looks better (and saves one character) using the latter. For me it's a 2-step process: Filename-to-Tag (%TITLE% only) and then convert Title tag. Assumes your filename is the way you want it, of course. This post has been edited by ThurstonX: Oct 15 2005, 02:17 |
|
|
|
Dec 28 2005, 16:12
Post
#13
|
|
![]() Moderator Group: Moderators Posts: 5506 Joined: 4-September 03 From: Germany Member No.: 201 Mp3tag Version: 2.55a |
Upper case for Roman numbers
Regular expression: \b(?:M{0,3})(?:D?C{0,3}|C[DM])(?:L?X{0,3}|X[LC])(?:V?I{0,3}|I[VX])(?=(\.\s|\s|\)|$)) Replace matches with: $upper($0) [ ] case-sensitive comparison This post has been edited by dano: May 7 2008, 15:37 -------------------- |
|
|
|
Feb 19 2006, 15:35
Post
#14
|
|
|
Member Group: Members Posts: 4 Joined: 16-February 06 Member No.: 2760 Mp3tag Version: 2.35 |
Convert artist names in the form 'Artist, The'
Regular expression: (.*),\sthe$ Replace with: The $1 This post has been edited by Snykch: Feb 19 2006, 15:43 |
|
|
|
Apr 22 2006, 13:56
Post
#15
|
|
|
Member Group: Full Members Posts: 7 Joined: 22-April 06 Member No.: 3051 Mp3tag Version: 2.35 |
And the other way around
Move "The " to the end Regular expression: ^The (.+) Replace with: $1, The So "The Cure" becomes "Cure, The" And "The a whole lot of words" becomes "a whole lot of words, The" |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 24th May 2013 - 07:38 |