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

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Thu Apr 27, 2017 2:56 am

kluv wrote:I do have the expanded version
Which version build do you have?
kluv wrote:if you would list the 5 presets I need I can start putting them together.
Actually, it should not be a need for a batch. The presets from the "Move field parts" menu are intended for such requests. The "Move rightmost part of <Into Field> between (and including) specified strings to +/- specified character position" could be used in your case with the following settings:
- Opening string: -
- Closing string: empty
- Remove opening string: checked
- Insert position: -6
- Prefix: empty
- Suffix: -

However, that preset and several another "rightmost" ones have a bug when the Closing string is empty. Here is the fixed Replace with string for this preset:

Code: Select all

RegSub(RegSub("$&", SetVar(0, "^(.*)(<If Caption="Use RegEx to specify strings" Value=0 ID=1><Else>" & RegSub("<End If><String Caption="Opening string" Value=" ("><If ID:1><Else>", "[$^*()+[\]\\{}|.?]", "\$$&") & "<End If>)(.*)(<If ID:1><Else>" & RegSub("<End If><String Caption="Closing string" Value=")"><If ID:1><Else>", "[$^*()+[\]\\{}|.?]", "\$$&") & "<End If>)"), "$1<If Caption="Remove opening string" Value="1"><Else>$2<End If><If Caption="Remove closing string" Value="1"><Else>$4<End If>"), IIf(<Number Caption="Insert position" Value="-1" MinValue="-100" ID:-1> >= 0, "^.{" & <ID:-1> - 1 & "}", ".{" & -<ID:-1> - 1 & "}$"), IIf(<ID:-1> >= 0, "$$&", "") & IIf(SetVar(1, Len(RegSub("$&", GetVar(0) & ".*|.*", "$2$3$4"))), "<String Caption="Prefix" Value=" [">", "") & RegSub("$&", GetVar(0) & ".*|.*", "<If Caption="Insert opening string" Value="0">$2<End If>$3<If Caption="Insert closing string" Value="0">$4<End If>") & IIf(GetVar(1), "<String Caption="Suffix" Value="] ">", "") & IIf(<ID:-1> < 0, "$$&", ""))
Thanks for bringing this into the light, so I could find that bug.
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

MMFrLife
Posts: 2774
Joined: Fri Oct 26, 2012 9:04 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by MMFrLife » Thu Apr 27, 2017 8:33 am

Thanks for fixing :)

Actually, a while back I noticed what I guessed to be a bug in more than one rightmost preset where they would only work if you counted from the left.
Not sure if those are ones you are referring to. I meant to report but forgot about the issue. I will have to look for it again later to confirm what they are.
MM user since 2003 (lifetime since 2012) "Trying to imagine life without music gives me a headache"
track properties; dir/fn mask configurations; check out ZvezdanD's scripts
MMW 4.1.18.1842b; fav scripts > RegExp Find & Replace 5.1.0; Magic Nodes 5.1.0; Advanced Duplicate Find & Fix 3.8.2;
Backup 6.0; Clear Now Playing Button 1.2
...always back it up, especially before doing anything major!!!
Win. explorer alt. for power users [free]; great file/folder renamer [used by nasa]

kluv
Posts: 17
Joined: Mon Oct 15, 2012 3:24 am

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by kluv » Thu Apr 27, 2017 5:25 pm

ZvezdanD wrote:Which version build do you have?
I have version 5.0.0.6.1


ZvezdanD wrote:- Opening string: -
- Closing string: empty
- Remove opening string: checked
- Insert position: -6
- Prefix: empty
- Suffix: -
After changing the code to what you have below I went to Tune and changed the values you mentioned. Nothing happened. I then checked the "Use RegEx to specify strings" and got this: Hear That First 12-$3$3-31-16. Not sure where I went wrong at.

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Fri Apr 28, 2017 1:26 am

kluv wrote:I have version 5.0.0.6.1
Didn't you get the newer versions by me? It is important that you use the latest version.
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

kluv
Posts: 17
Joined: Mon Oct 15, 2012 3:24 am

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by kluv » Fri Apr 28, 2017 2:55 pm

ZvezdanD wrote:Didn't you get the newer versions by me? It is important that you use the latest version.
Would it have been sent in an email?

What do I need to do to get it?

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Fri Apr 28, 2017 3:07 pm

kluv wrote:Would it have been sent in an email?
How else would I sent you updates? ;)

The last one was sent on 2017-03-15, please check your Spam folder and if it is there put my e-mail address on your contact list to prevent such things in the future.
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

kluv
Posts: 17
Joined: Mon Oct 15, 2012 3:24 am

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by kluv » Fri Apr 28, 2017 7:54 pm

It worked like a dream. Thank you for your help!!

TLD
Posts: 27
Joined: Sat Jun 27, 2009 6:11 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by TLD » Sun Jun 04, 2017 1:27 am

FYI - I can't find any of the presets for a "Trim" feature, getting rid of spaces at the beginning/end of the fields...

so I made one!

Named "Trim"
Description: "Trim whitespace from ends of fields"
Find what: "^\s*(.*[^ ])\s*$"
Replace with: "$1"
Regular Expression 1 checked

Searches for whitespace followed by "anything" not ending with a space, and more whitespace - whitespace at beginning or end is optional (0 or more)
Replaces with the "anything"
So it can be run against the entire library if you choose.

Just thought I'd share...

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Sun Jun 04, 2017 5:54 am

TLD wrote:FYI - I can't find any of the presets for a "Trim" feature, getting rid of spaces at the beginning/end of the fields...
Preset65=Name: "Remove leading and trailing spaces from <Into Field>..."
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

TLD
Posts: 27
Joined: Sat Jun 27, 2009 6:11 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by TLD » Fri Jun 09, 2017 10:01 pm

ZvezdanD wrote:Preset65=Name: "Remove leading and trailing spaces from <Into Field>..."
Well... mine is different... :)

Seriously; missed it among the other 250+... but hey - great minds and all that, right?

Differences are small, but could make a difference...
65's is "^(\s*)(.*?)(\s*)$"
Mine is "^\s*(.*[^ ])\s*$"

Biggest differences are 65's performs capture of the spaces, and mine watches for a non-space...

Also, the capture for 65 leaves room for capture of a space...
(.*?) looks for any number of characters - non-greedy
(.*[^ ]) looks for any number of characters not ending with a space (...and I should have used ^\s...)

A problem I see is 65's might see " two spaces " and end up with "two spaces " with a space on the end because it only needed to take the one on the end for the match.

but yeah - thank you for pointing out the one I missed... :)

Now; is there any in there that can reorder artists separated by semicolons so they're alphabetical? :)
I want "Artist Two" to come before "First Artist", but the artist field is "First Artist; Artist Two" - and some have three, four, and ...I think the most is seven artists. Might be more. (Musical soundtrack... heck; The Sound of Music has the seven children, Herr and Frau... so nine!)
I'm writing VB for it now... in my spare time... but if something already exists... ;)

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Sat Jun 10, 2017 1:55 am

TLD wrote:Biggest differences are 65's performs capture of the spaces, and mine watches for a non-space...

Also, the capture for 65 leaves room for capture of a space...
(.*?) looks for any number of characters - non-greedy
(.*[^ ]) looks for any number of characters not ending with a space (...and I should have used ^\s...)

A problem I see is 65's might see " two spaces " and end up with "two spaces " with a space on the end because it only needed to take the one on the end for the match.
Sorry, but I don't know what you are talking about. The Preset 65 works just fine. As its name says, it removes spaces both leading and trailing. If you tried it, you would know that it replaces " two spaces " with "two spaces" without space on the end.

By the way, I updated that preset in v5.x to:
Find what: ^\s+|\s+$
Replace with: empty

The result of the replacement is the same, but now it could be used to actually find files that begin or end with spaces.
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

TLD
Posts: 27
Joined: Sat Jun 27, 2009 6:11 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by TLD » Sun Jun 11, 2017 4:38 pm

ZvezdanD wrote:Sorry, but I don't know what you are talking about. The Preset 65 works just fine. As its name says, it removes spaces both leading and trailing. If you tried it, you would know that it replaces " two spaces " with "two spaces" without space on the end.
I'm working with regular expressions a lot at work, and we do our best to try and avoid potential false positives/false negatives with the searches.

As an example - just using "\s$" will find a space at the end... but if there were two, only the last one would match, and the other would remain.

My previous note about the existing 65:
TLD wrote:(.*?) looks for any number of characters - non-greedy
It could lead to finding a string including spaces at the end, so long as there's something to match the end of the string.

I didn't make the note to cause strife or start any kind of argument - I was merely noting that the way it was written allows for ambiguity in the match.
Using "(/s+)(.*?)(/s+)", the entry " Two Spaces " could be matched "/ /Two Spaces/ /", "/ /Two Spaces / /" or even "/ /Two Spaces "

To remove the ambiguity, I added [^/s] to make it (.*[^/s]) and thus the last character of the matching phrase will *not* be a space. (.* could match any number of spaces on its own, but if all you have is spaces, they should all be "eaten" by the first ^\s*, and another \s*$ at the end would match any number of spaces at the end.
This makes " a " be matched and rewritten as "a" without any ambiguity on the number of spaces.

Unintended consequences could destroy a library.

The way you said you rewrote it, by the way, matches at the beginning OR the end, so for normal regex use, you'd need to run it twice to catch both.

ZvezdanD
Posts: 3094
Joined: Thu Jun 08, 2006 7:40 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by ZvezdanD » Mon Jun 12, 2017 2:20 am

TLD wrote:I didn't make the note to cause strife or start any kind of argument
Yes, you did. You claim that my preset doesn't work as it should (and that it could even destroy the library) without actually trying it. Could you give at least one example where it is not working?
TLD wrote:The way you said you rewrote it, by the way, matches at the beginning OR the end, so for normal regex use, you'd need to run it twice to catch both.
Again, you claim something against my preset without actually trying it. The updated preset doesn't need to run twice to catch both the begin AND the end.

The name of my preset is "Remove leading and trailing spaces from <Into Field>...". It is "spaces" (plural), not "space" (singular). There is no ambiguity with it, it will remove one, two or any number of spaces both from the begin AND/OR end.
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  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.2  Add Currently Playing/Selected Track(s) to Playlist 1.1.2

Shokri4971@gmail.com

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by Shokri4971@gmail.com » Wed Jun 21, 2017 6:32 am

hi, thank you for you perfect plugin.

how can I edit the code to has this possibility to find and replace in multiple field, for example search in Artist and Album field

MMFrLife
Posts: 2774
Joined: Fri Oct 26, 2012 9:04 pm

Re: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [M

Post by MMFrLife » Mon Jul 03, 2017 11:47 am

I'm trying to add a string to the beginning of a folder level in the path.
It feels like I've dome something like this before, but I've just gone blank.
Can you point me to the right preset or one as foundation for manipulation.

Also, is there a way to choose any "<From Field> to <Into Field>" preset and
manipulate a control(s) to limit it to just the "<Into Field>"
MM user since 2003 (lifetime since 2012) "Trying to imagine life without music gives me a headache"
track properties; dir/fn mask configurations; check out ZvezdanD's scripts
MMW 4.1.18.1842b; fav scripts > RegExp Find & Replace 5.1.0; Magic Nodes 5.1.0; Advanced Duplicate Find & Fix 3.8.2;
Backup 6.0; Clear Now Playing Button 1.2
...always back it up, especially before doing anything major!!!
Win. explorer alt. for power users [free]; great file/folder renamer [used by nasa]

Post Reply