RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [MM2+]

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by nynaevelan »

Hi:

I need a little help again. I would like to setup a preset that would search the lyrics field for any non-English alphabet characters, is this possible? I don't need to replace them, I just want to identify them in order to replace the lyrics with a different script.

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

nynaevelan wrote:I would like to setup a preset that would search the lyrics field for any non-English alphabet characters, is this possible?
Of course it is possible. For example you could take a look on the "Capitalize the Title (ASCII, Latin 1, Latin 2 & Cyrillic)" preset which contains character ranges.

If you want to find a field which contain English alphabet characters, you should write the next string for the Find what:

Code: Select all

[A-Za-z]
Now, if you want just opposite, i.e. to find any character which is not English alphabet, you should add "^" inside of the brackets on the begin:

Code: Select all

[^A-Za-z]
However, there is a problem with such string because it would match all non-alphabet characters like numbers, punctuation... So, it is the best if you specify all character ranges which you want to find - [\xDF-\xF6\xF8-\xFF] is Latin1, [\u0100-\u024F] is Latin2 and [\u0400-\u04FF] is Cyrillic. If you want to cover all of this ranges, you should write:

Code: Select all

[\xDF-\xF6\xF8-\xFF\u0100-\u024F\u0400-\u04FF]
nynaevelan wrote:I don't need to replace them, I just want to identify them in order to replace the lyrics with a different script.
I don't know exactly what you want, but I think that even this could be done automatically with this script.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by nynaevelan »

Will you examples catch Chinese characters also?

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

nynaevelan wrote:Will you examples catch Chinese characters also?
No, it will match only Latin 1, Latin 2 and Cyrillic. If you are interested about character ranges, please take a look on http://www.unicode.org/Public/UNIDATA/Blocks.txt or http://www.regular-expressions.info/unicode.html.

Anyway, if you want to find all non-ASCII characters, you could try with:

Code: Select all

[^\x20-\x7F]
or:

Code: Select all

[^\u0020-\u007F]
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
barkoz
Posts: 121
Joined: Fri May 02, 2008 5:58 pm
Location: Sydney, Australia

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by barkoz »

I need a little help, I am trying to remove the timing marks from LRC lyrics
From this
[00:13]E già
[00:15]Io sto sempre con gli altri
[00:19]Però

and get this
E già
Io sto sempre con gli altri
Però

In Find What I put [:\d] using regular expression 1 and that gives me
[]E già
[]Io sto sempre con gli altri
[]Però

Is there any way of removing all, those brackets are killing me, I will never get to sleep tonight. :o :o :o
Any help would be much appreciated
Cheers from down here.


EDIT
Never mind... I got it. Had to use
[][:\d]
I Love This Script
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

barkoz wrote:Never mind... I got it.
Glad you found your way to do this. :) However, I think this is not the best approach for such thing because it would remove all occurrences of specified characters, even if they are not a part of timing marks - "[", "]", ":" and digits from "0" till "9". This is because square brackets are reserved characters in RegExp and they are used for specifying character classes. If you want to specify square brackets as plain characters you should put backslash in the front of them - \[ and \].

There are several more appropriate solutions to your request, here is the simplest one:

Code: Select all

\[\d\d:\d\d\]
If you want more complicated one, you could check if a position of matched characters are on the begin of each line, for example:

Code: Select all

(^|\r\n)(\[\d\d:\d\d\])
but in this case you should use $1 as a Replace with string.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
djo4ever
Posts: 1
Joined: Tue Sep 02, 2008 12:13 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by djo4ever »

Hello,
Is it possible to replace more words on the same line at once?

I want to do the following thing:

Find one of these words: ft,feat,vs, Versus
and replace it with: ;
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

djo4ever wrote:Is it possible to replace more words on the same line at once?
Yes, it is.
djo4ever wrote:Find one of these words: ft,feat,vs, Versus
and replace it with: ;
Did you tried the suggestion described at http://www.mediamonkey.com/forum/viewto ... 20#p163520?
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
barkoz
Posts: 121
Joined: Fri May 02, 2008 5:58 pm
Location: Sydney, Australia

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by barkoz »

ZvezdanD wrote
Glad you found your way to do this. However, I think this is not the best approach for such thing because it would remove all occurrences of specified characters, even if they are not a part of timing marks - "[", "]", ":" and digits from "0" till "9". This is because square brackets are reserved characters in RegExp and they are used for specifying character classes. If you want to specify square brackets as plain characters you should put backslash in the front of them - \[ and \].
Thank's mate,I hadn't realised that, is there anything this script can't do besides the dishes? :D :D :D
gege
Posts: 866
Joined: Tue Sep 05, 2006 2:10 pm
Location: Brazil

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by gege »

barkoz wrote:Thank's mate,I hadn't realised that, is there anything this script can't do besides the dishes? :D :D :D
I'm almost sure it can't do the laundry too... but who knows :roll:
MCSmarties
Posts: 251
Joined: Tue Dec 06, 2005 8:01 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by MCSmarties »

Wow this script is powerful! Many thanks!

I have mainly been using it to work on lyrics and noticed a small nit-pick:

The preset "Uppercase the first letter of each line of the Lyrics" is not ideal.
Currently, it uppercases the first character but sets everything else in lower case!
Anything that was capitalized before is now lower case, including for examples place
names and pronouns ("i am" vs "I am").

An easy fix is to change the replace with field:

Code: Select all

UCase("$1") & LCase("$2")
should be replaced with

Code: Select all

UCase("$1") & "$2"
Of course, this assumes that the ONLY capitalization problem with the lyrics was the first letter of each line...

Another alternative I found is a simple preset to always capitalize the pronoun "I", as follows:

Code: Select all

Uppercase "i" in the Lyrics
Find what: \bi\b
Into: Lyrics
Replace with:I
Match case: checked
That got me thinking, would it be possible to make a preset that would replace all kinds of words with others?
Like "cos", "cuz" with "cause" (a pet peeve of mine), or add apostrophes where missing (im, ill, dont, wont -> I'm, I'll, don't, won't)

Your script uses an extremely powerful algorithm, I think it would be great to incorporate it into a dedicated
"lyrics cleanup script" with user-defined replacements. Combined with das Monkey's amazing "Lyricator" script,
it would make adding lyrics a breeze indeed!
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

MCSmarties wrote:The preset "Uppercase the first letter of each line of the Lyrics" is not ideal.
Currently, it uppercases the first character but sets everything else in lower case!
Yes, I am aware about the English word "I" (http://www.mediamonkey.com/forum/viewto ... 44#p163244), and there is also a problem with personal names which should have first character uppercased.
MCSmarties wrote:Of course, this assumes that the ONLY capitalization problem with the lyrics was the first letter of each line...
Well, this is just one more problem for such implementation. What if someone has a lyrics with all characters in uppercase? How about languages where "I" should not be uppercased? Believe it or not, in my language the word "I" has a meaning of "and" in English and it should be lowercased when it is in sentence.

Anyway, I am thinking to introduce one more preset for the next version of this script which would be same as mentioned preset, except it would uppercase the word "I" and maybe it would have a rather limited list of English personal names (of course, this list would be user-customizable).
MCSmarties wrote:would it be possible to make a preset that would replace all kinds of words with others?
Like "cos", "cuz" with "cause" (a pet peeve of mine), or add apostrophes where missing (im, ill, dont, wont -> I'm, I'll, don't, won't)
Of course it is possible. There are already included some presets which are doing similar thing, even within only one step. Just take a look at the preset "Fix common words (featuring, presents, versus)" or "Remove diacritical marks from the Title" - with a single preset you could replace many characters or words to another characters or words: Feat, feat, Feat., feat., Featuring, featuring, Features, features, Ft, ft, Ft. are all converted to ft., then Presents, Presenting ... to pres. and Versus, Vs ... to vs.. It is all possible with a help of the custom VB function MapArray.

Here are settings for your example:
Find what:

Code: Select all

\b(?:(cos|cuz)|([Ii]m)|([Ii]ll)|(dont)|(wont))\b
Replace with:

Code: Select all

MapArray(Array("$1", "cause", "$2", "I'm", "$3", "I'll", "$4", "don't", "$5", "won't"))
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
xabaras
Posts: 1
Joined: Wed Oct 15, 2008 9:49 am

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by xabaras »

I apologize if this question has been answered already but I was curious if there would be a way to use the 'fix featured' routine and modify it so that I could make the Title of the song have featured artist instead of the artist.. example:

From
------
Artist: 112 featuring Lil'z
Title: Anywhere

To
----
Artist: 112
Title: Anywhere (feat. Lil'z)

Any help would be great... you have a get product I am just really lame when it comes to coding
ZvezdanD
Posts: 3257
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by ZvezdanD »

xabaras wrote:if there would be a way to use the 'fix featured' routine and modify it so that I could make the Title of the song have featured artist instead of the artist..
Have you tried a suggestion described at http://www.mediamonkey.com/forum/viewto ... 36#p154236?
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
Owyn
Posts: 2018
Joined: Fri Mar 21, 2008 10:55 am
Location: Canada

Re: RegExp Find & Replace 2.2.2 - with 50 presets [MM2+3]

Post by Owyn »

Thanks for the script. Should have got it a while ago.
Cogito cogito ergo cogito sum. (Ambrose Bierce)
I drink therefore I am. (Monty Python)
Vista 32bit Home Premium SP2 / MM3.2.1.1297 Gold / Last.Fm 1.0.2.22 / IE8
Dell Inspiron 530 (1.8 Core2 / 2GB)
Skin: Vitreous Blue
Scripts: Add/Remove Playstat|Advanced Duplicate Find & Fix|Album Art Tagger|Backup|Batch Art Finder|Calculate Cover Size|Case&Leading Zero Fixer|DB_Audit|DB_Clean|DB_Schema|Event Logger|Genre Finder|Lyricator|Magic Nodes|MM2VLC|Monkey Rok|MusicIP Tagger|PUID Generator|RegExp Find & Replace|Right Click for Scripts|Scriptreloader|SQL Viewer|Stats(Filtered)|Tagging Inconsistencies
Post Reply