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  < 1 2 3 4 >  
Closed TopicStart new topic
> Regular Expressions, Examples of actions with Regular Expressions
RevRagnarok
post Aug 17 2010, 13:57
Post #31


Member


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



QUOTE (d003232 @ Aug 16 2010, 06:38) *
I do it the way:

Field: TITLE
RegExp: (.*).\[[0-9]+kb\s[0-9]+khz.*\]
Replace with: $1

FYI, that is slightly incorrect. It will actually remove 1 character from before the '[' which in your example is '.' - you need to escape the '.' to ensure it is a '.':
Field: TITLE
RegExp: (.*)\.\[[0-9]+kb\s[0-9]+khz.*\]
Replace with: $1

Another simpler option would be to just grab everything before the first dot:
Field: TITLE
RegExp: ([^\.]*)
Replace with: $1

Or if you want everything up to the first '[' but no period, why bother matching what is in the brackets unless you planned on parsing it for something else?

Field: TITLE
RegExp: (.*)\.\[
Replace with: $1


I am at work, so this is all untested RE code.
Go to the top of the page
 
+Quote Post
DetlevD
post Aug 31 2010, 10:33
Post #32


Member


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



Roman numerals in uppercase

This "Regular Expression" changes Roman numerals in uppercase.
Valid range of numbers: "I" to "MMMCMXCIX" (decimal: 1-3999).

Dieser "Reguläre Ausdruck" ändert römische Ziffern in Großbuchstaben.
Gültiger Zahlenbereich: "I" bis "MMMCMXCIX" (dezimal: 1-3999).

Example
From:
"ab i ab ii ab iii iv v vv vi vii viii ix abc x mcmliv ll cmm mmix-ix-xi"
To:
"ab I ab II ab III IV V vv VI VII VIII IX abc X MCMLIV ll cmm MMIX-IX-XI"

CODE
$regexp(%TITLE%,'\b(?i:(?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?X{0,3})|L)?((I[VX])|(V?(I{0,3}))|V)?))\b','\U$0')



Alternative:
(using the 'ignore case' parameter of the Mp3tag $regexp function instead of regex modifier)
CODE
$regexp(%TITLE%,'\b(?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?X{0,3})|L)?((I[VX])|(V?(I{0,3}))|V)?)\b','\U$0',1)



Attached is a Mp3tag mte export script, which visualizes the results of three attempts using regular epressions, which are able to upcase Roman Numerals in different quality.
Attached File  Test.RomanNum.Upcase.zip ( 1.95K ) Number of downloads: 337


DD.20100831.1133.CEST
Edit. Spelling error in RegEx corrected and zip file attached.
DD.20110320.1518.CET

This post has been edited by DetlevD: Mar 20 2011, 15:28


--------------------
* 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 Sep 17 2010, 18:02
Post #33


Member


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



Splitting an "Upper Camel Case" string

The following "Regular Expression" splits an "Upper Camel Case" string into components by inserting a space character before any Word which starts with a capital letter or digit.

Der folgende "Reguläre Ausdruck" teilt eine Zeichenkette mit Binnenmajuskeln in Komponenten auf durch Einfügen eines Leerzeichens vor jedem Wort, das mit einem Großbuchstaben oder einer Ziffer beginnt.

Example
From:
"ThisIsThe2ndSongFromD.D.'sFirstAlbum30YearsAgo."
To:
"This Is The 2nd Song From D.D.'s First Album 30 Years Ago."

CODE
$regexp(%_FILENAME%,'(?<!^)(\u\l|(?<=\l)[\u\d])',' $1')


DD.20100917.1902.CEST

Attached Image

Edit.DD.20110816.1848.CEST

This post has been edited by DetlevD: Aug 16 2011, 17:48


--------------------
* 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
InspectorMustach...
post Dec 6 2010, 01:09
Post #34


Member


Group: Full Members
Posts: 14
Joined: 31-March 10
Member No.: 12175
Mp3tag Version: 2.51



QUOTE (nickless @ Mar 29 2005, 22:22) *
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")

This didn't work for me. I tried to make my own and came up with this simple RegEx to get the cases right in my tags:

REGULAR EXPRESSION:
\b(?<!')(\w)
REPLACE WITH:
\u\1

This works for me. You can apply this to the _ALL field but be aware that this capitalizes your extensions too. If this looks somehow annoying to you (as it does to me), simply apply this to the _FILENAME field afterwards:

REGULAR EXPRESSION:
\.([^\.]+)$
REPLACE WITH:
.\L\1\E

These are both pretty simple but I spent quite a time figuring out how to make these apply for Unicode. I finally found out that Mp3tag has Unicode functionality standardly implemented into its RegEx engine. Heh. biggrin.gif


Edit: Here's some improvement. The last one only replaced the first letter of the word and put it into upper case disregarding the rest of the word. This one also puts those that follow the first letter into lower case ("DAItro" becomes "Daitro"):

REGULAR EXPRESSION:
\b(?<')([a-zA-Z])([^']*?)\b
REPLACE WITH:
\u\1\L\2\E

This next one is basically the same but takes note of the French article L' and puts the letter following the article into upper case. So, for example, "L'eau" becomes "L'Eau".

REGULAR EXPRESSION:
\b(?<!(?<!\s[Ll])')([a-zA-Z])([^']*?)\b
REPLACE WITH:
\u\1\L\2\E

This post has been edited by InspectorMustache: Dec 6 2010, 12:58
Go to the top of the page
 
+Quote Post
Juozas V
post Dec 15 2010, 02:39
Post #35


Member


Group: Members
Posts: 1
Joined: 15-December 10
From: Edinburgh, United Kingdom
Member No.: 13412
Mp3tag Version: 2.47a



Script to fix capitalization according to English rules only in tags. This is my n-th attempt to do this, but I think it works quite nice... Of course some human work is needed because it doesn't contain corpus to check it according to its POS.

CODE
[#0]
T=1
F=_TAG
1=1
2=

[#1]
T=4
F=_TAG
1=\\b(A|An|The|And|But|Or|So|After|Before|Out|When|While|Since|Until|Although|Even If|Because|About|Above|Across|Against|Along|Alongside|As|At|Below|By|During|For|
From|In|Into|Of|Off|On|Onto|Over|Than|Through|Till|To|Under|Up|With|Within|Witho
u
t)\\b
2=$lower($1)
3=0

[#2]
T=4
F=_TAG
1=^\\s*(\\w+)
2=$caps($1)
3=0

[#3]
T=4
F=_TAG
1=(\\w+)\\s*$
2=$caps($1)
3=0


Or directly in mp3tag:
Case conversion
Field _TAG
Case conversion Mixed Case
Words begin...

Replace with regular expression
Field _TAG
Regular expression \b(A|An|The|And|But|Or|So|After|Before|Out|When|While|Since|Until|Although|E
ven If|Because|About|Above|Across|Against|Along|Alongside|As|At|Below|By|During|For|
From|In|Into|Of|Off|On|Onto|Over|Than|Through|Till|To|Under|Up|With|Within|Withou
t)\b
Replace matches with $lower($1)

Replace with regular expression
Field _TAG
Regular expression ^\s*(\w+)
Replace matches with $caps($1)

Replace with regular expression
Field _TAG
Regular expression (\w+)\s*$
Replace matches with $caps($1)

This post has been edited by Juozas V: Dec 15 2010, 02:47
Go to the top of the page
 
+Quote Post
DetlevD
post Jan 10 2011, 19:09
Post #36


Member


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



Regular Expression Tutorial

Beginner or Professional!
Please take a few minutes and look this presentation (slideshow or PDF):

Andrei’s Regex Clinic

This is an outstanding work, which visualises the world of Regular Expressions in a wide manner.
The tutorial can help to open your mind.

http://zmievski.org/c/dl.php?file=talks/co...egex-clinic.pdf
http://www.slideshare.net/andreizm/andreis-regex-clinic
http://zmievski.org/2010/05/regex-clinic-on-slideshare

DD.20110110.1912.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
pone
post Jan 10 2011, 21:02
Post #37


Member


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



ZITAT(DetlevD @ Jan 10 2011, 19:09) *
Regular Expression Tutorial

Beginner or Professional!
Please take a few minutes and look this presentation (slideshow or PDF):

Andrei’s Regex Clinic

Are all the things described there useable for mp3tag?
Go to the top of the page
 
+Quote Post
DetlevD
post Jan 10 2011, 21:09
Post #38


Member


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



QUOTE (pone @ Jan 10 2011, 21:02) *
Are all the things described there useable for mp3tag?

Probably not, one must abstract.

DD.20110110.2111.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
Doug Mackie
post Jan 13 2011, 19:55
Post #39


Member


Group: Full Members
Posts: 37
Joined: 27-April 09
From: New Jersey, USA
Member No.: 9952
Mp3tag Version: 2.51



To Juozas V:
Thank you very much for this. It does the best English title case conversion that I have seen here.

However, I have one minor quibble. Your word list includes some words and phrases that I see more often used in song titles as subordinate conjunctions than as prepositions. For example "after", "because", and "although". From my reading on capitalization in titles, subordinate conjunctions should always be capitalized. Since it's not practical to use script to detect how a word is used, I chose to remove those words from your Reg Ex on the basis that there should be fewer errors without them than with them. The words that I removed are:

After, As, Although, Because, Even If, Since, Till, Until, When, and While.

Here is my revised word list (resorted alphabetically):

A|About|Above|Across|Against|Along|Alongside|An|And|As|At|Before|Below|But|By|Du
ring|For|From|In|Into|Nor|Of|Off|On|Onto|Or|Out|Over|So|Than|The|Through|To|Unde
r
|Up|With|Within|Without


Note that I also added the coordinating conjunction "Nor" to your list.

Best regards,
Doug M. in NJ

This post has been edited by Doug Mackie: Jan 13 2011, 19:58
Go to the top of the page
 
+Quote Post
LosMintos
post Apr 18 2011, 20:55
Post #40


Member


Group: Full Members
Posts: 88
Joined: 23-September 08
Member No.: 7617
Mp3tag Version: 2.51



Convert MP3tag's date to ISO date

Converts (example) 18.04.2011 to 2011-04-18.

format tag field
Field: date added
Format string: %_date%

replace with regular expression
Field: date added
RegExp: ^(\d+)\.(\d+)\.(\d+)$
Replace with: $3-$2-$1
Go to the top of the page
 
+Quote Post
Zoofield
post Jun 10 2011, 22:17
Post #41


Member


Group: Full Members
Posts: 7
Joined: 17-July 06
Member No.: 3449
Mp3tag Version: 2.49



I could not get, "DetlevD - Splitting an Upper Camel Case string" to work, although I like the idea!

These together:
CODE
RE:Adds a space between Capital and lowercase letter or digit behind it.
Field:_Tag
re:([^A-Z\W\_])([A-Z])(?=[^A-Z])
($1) ($2)

RE:Adds a space between Digit and lower case letter behind it
Field:_Tag
re:([^\W\d\_])(\d)
($1) ($2)

Will...

Example.
From:
"ThisIsThe2ndSongFromD.D.'sFirstAlbum30YearsAgo."
To:
"This Is The 2nd Song From D.D.'s First Album 30 Years Ago."


This is the two above combined:
CODE
RE:Adds a space between, Capital and lowercase letter or digit behind it, Digit and lower case letter behind it.
Field:_Tag
re:([^A-Z\W\_])([A-Z])(?=[^A-Z])|([^\W\d\_])(\d)
$1$3 $2$4

Does the same except in the case of...

CapitalWord9CapitalWord2ndSong30Years

Example.
First pass will: Capital Word9 Capital Word 2nd Song 30 Years
Second pass will: Capital Word 9 Capital Word 2nd Song 30 Years
Third pass will: Reveal A Latent O.C. Disorder

Because the single digit '9' in the example can only be captured once per pass per replacement.

I would use the first set for completeness and through the "Action Groups".
I would use the Second for brevity and through "Actions (Quick)"

This post has been edited by dano: Jun 11 2011, 17:08


--------------------
Go to the top of the page
 
+Quote Post
tobi06
post Jun 18 2011, 11:01
Post #42


Member


Group: Members
Posts: 1
Joined: 18-June 11
Member No.: 14714
Mp3tag Version: 2.49



To remove any website in the filename


example: artist - title[www.whateverwebsite.com].mp3
artist - title.mp3

regular expression: \[.{3}\.\w*\..{3}\]
Go to the top of the page
 
+Quote Post
gingernob
post Jun 19 2011, 18:06
Post #43


Member


Group: Members
Posts: 4
Joined: 5-April 10
Member No.: 12217
Mp3tag Version: 2.46a



QUOTE (areve @ Oct 16 2003, 21:42) *
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)



OK, i know im being dumb, just this reg ex stuff is over my head..u might just as well speak japanese to me.
All the examples i find talk of removing ## - [track title] to [track title]
i just want ## [track title] to [track title]...no dash.
appreciate a 'simple' answer for simpleton.
Go to the top of the page
 
+Quote Post
dano
post Jun 19 2011, 20:14
Post #44


Moderator


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



I've added an example without dash to that post.


--------------------
Go to the top of the page
 
+Quote Post
gingernob
post Jun 20 2011, 01:39
Post #45


Member


Group: Members
Posts: 4
Joined: 5-April 10
Member No.: 12217
Mp3tag Version: 2.46a



QUOTE (dano @ Jun 19 2011, 21:14) *
I've added an example without dash to that post.

Thank u so much...
Go to the top of the page
 
+Quote Post

4 Pages V  < 1 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: 25th December 2014 - 12:28