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

Post a reply

Visual Confirmation

To prevent automated access and spam, you are required to confirm that you are human. Please place a check mark next to all images of monkeys or apes. If you cannot see any images, please contact the Board Administrator.

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: RegExp Find & Replace 4.3 w/ 253 presets (2011-07-06) [MM2+]

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

Post by ZvezdanD » Wed Nov 29, 2017 2:00 am

I don't understand why you don't want to use the predefined "Assign" preset that I mentioned, which already does what you want. Presets are nothing more than saved replacement settings, using regular expressions or not. So, if you want to know how its settings looks, you could just choose it from the Preset combo box.

By the way, the Usage section of the add-on's Web page contains explanation about the purpose of Find what/Replace with strings and how they could be used:
"The first control in the next (finding) group is the Find what combo box which is used to specify the string that we want to search for and/or to replace in the destination field.
...
The first control in the next (replacing) group is the Replace with combo box which could be used for specifying a string that we want to use for the replacement."

Now, think again what you want to replace and what you want to use as a replacement.

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

Post by Spix » Tue Nov 28, 2017 7:04 pm

Hi,

thank you for yours answer!

Still I don't understand, why my approach with regular expressions does not work (for the first part of moving, i.e. copying the artist to the artist field)!?
Do you have an idea why it is not working? I'm still interested to make it work with regular expressions!

For this special problem I found an easy solution with the help of "Auto-Organize of Files..." and "Auto-Tag from File..."

Best regards
Spix

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

Post by ZvezdanD » Mon Nov 27, 2017 12:52 pm

Copying a (part of a) string from a source to destination field modifies only destination field, so it could be done using a single preset's settings. However, moving a (part of a) string from a source to destination field requires modification of both fields, source and destination, which is not directly supported by this add-on using a single preset's settings. If you want to modify several fields, you could do that most easily with several appropriate presets applied in sequence.

By the way, the donation-only version currently has 28 moving presets that modify both source and destination fields at once, including "Move the begin of <From Field> before leftmost specified string to <Into Field>".

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

Post by Spix » Mon Nov 27, 2017 3:42 am

Thank you for your quick response!

I'm not sure whether I got it:
I don't want to use a preset at all but just use regular expressions and I think I need regular expression 2 to move a (part of a) string from field Tittle to field Artist??
I tried with 2 capturing groups "(.*)" but with the same result:

Find what: "(.*) - (.*)" | Into: Artist | Regular expression 1: marked | without "Full" and "Find whole words only"
Original: "Unknown Artist"

Replace with: "$2" | From: Title | Regular expression 2: marked | without "Full", "VBScript", "Match case", "Backward search direction"
Replacement: "myTitle - myBand"
Result: "Unknown Artist"


Best regards
Spix

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

Post by ZvezdanD » Mon Nov 27, 2017 1:52 am

You don't have any capture group in the Find what regular expression, so $2 cannot replace anything. Also, Regular expression 2 should not be turned on in your case.

The freely available version of the add-on doesn't have a single predefined preset to move a part of the source field to the destination field at once. However, there is several predefined presets that could be used to copy the begin of the source field before the " - " to the destination, e.g. "Assign the begin of <From Field> before "" - "" to <Into Field>", or "Assign the begin of <From Field> before specified string to <Into Field>". After that you could use another preset to remove that begin from the source field, e.g. "Remove the begin of <Into Field> before (and including) "" - """ or "Remove the begin of <Into Field> before (and including) specified string".

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

Post by Spix » Sun Nov 26, 2017 8:55 pm

Hi,

I have a a song with title "myTitle - myBand" in my MM database and want to use regular expressions to move the part "myBand" to the artist field.

So I tried:
Find what: ".* - .*" | Into: Artist | Regular expression 1: marked | without "Full" and "Find whole words only"
Original: "Unknown Artist"

Replace with: "\2" or "$2" | From: Title | Regular expression 2: marked | without "Full", "VBScript", "Match case", "Backward search direction"
Replacement: "myTitle - myBand"
Result: "Unknown Artist"


I expected the Result: "myBand" but get "Unknown Artist" !

In general I'm familiar with regular expressions, so I'm very interested to find my bug!
Does anybody have an idea what I'm doing wrong?

Best regards
Spix

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

Post by ZvezdanD » Thu Nov 16, 2017 4:44 am

You are right, it was flipped. Thanks for the report. Here is the fixed Replace with string:
<If Caption="Assign to the field" Value=1 ID=1><From Field><Else Caption="Append to:"><If Caption="the begin of field" Value=1 ID=2><From Field><Else Caption="the end of field">"$_"<End If> & IIf(Len("$_") > 0 And Len(<From Field>) > 0, "<String Caption="Separator" Value=" - " ID=3>", "") & <If ID:2>"$_"<Else><From Field><End If><End If>

You don't need to (actually, you shouldn't) use the Entire/Begin button with the mentioned preset. That button is an extension of the Full button from the freely available version with added some new options. It doesn't represent any preset's parameter/option and its state is not saved with the preset. It is just a short way to insert to/replace Find what or Replace with string with some predefined pattern, e.g. with the Entire item you will get "^.*" which is the Regex replacement for the full content of the field. The mentioned preset has that thing already defined in the Find what and Replace with strings, it is enough to customize it using the Tune dialog box.

By the way, it is always recommended that you use the presets supplied with the latest version of the add-on using a guide mentioned in the Installation section, because many preset could be updated/improved, which is a fact that I mentioned in the What Is New section.

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

Post by MMFrLife » Wed Nov 15, 2017 8:49 pm

Ok, so I updated to the proper one (with the exact same tuner display as shown above) and noticed that when I
use Append - to begin it does it to the end, and Append - to the end puts it at the begin.
If I use Assign, then change Entire to begin, it basically works but no space.

Is the code accidentally flipped or something. I tried it on different non-numerical fields and got the same flipped results.

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

Post by MMFrLife » Wed Nov 15, 2017 7:25 pm

Yes, I figured out the problem. I used that preset from an older one before many of the parameters were consolidated".
Although, sometimes I just forget to use the tuner. When I first learned it, I use to do almost everything directly
and just kept doing it that way. I'm better now, but that habit still haunts me on occasion.

Thanks!

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

Post by ZvezdanD » Wed Nov 15, 2017 5:14 pm

MMFrLife wrote:If I use "Copy <From Field> to <Into Field>..." and set Entire to Begin, how would I insert
a space between the beg. string and the original string?

Which version of the preset are you using? The latest one has tags that allow appending to the begin/end with specified separator without need to modify Find what or Replace with strings directly.

Image

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

Post by MMFrLife » Wed Nov 15, 2017 2:26 pm

Thanks, those are the elements I was trying to find/insert somewhere. I just couldn't get them exact :( , but now :D .

Similar to the above example:

If I use "Copy <From Field> to <Into Field>..." and set Entire to Begin, how would I insert
a space between the beg. string and the original string?

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

Post by ZvezdanD » Sat Nov 11, 2017 4:26 pm

MMFrLife wrote:Is there a way to insert a space before it, using that same preset (without batching something to it)?

Add " " & at the begin of the Replace with string.

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

Post by MMFrLife » Sat Nov 11, 2017 4:26 am

I'm using "Auto-increment Track number with specified starting value and leading zero(es)...". I have it set from Entire to End of Into field.
Is there a way to insert a space before it, using that same preset (without batching something to it)?

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

Post by mhendu » Tue Oct 24, 2017 7:04 pm

ZvezdanD wrote:
mhendu wrote:I'm using a modified version of one of the presets of this script to try to source the year and copy that over but I'm no SQL or regular expressions expert

If you are using a modified version, then I suppose you know at least VBScript. You could use Left(..., 4) to get the leftmost 4 characters of any string.


Thanks. I have no idea what I'm doing but I managed to figure that out. Just added Left(...,4) around the VBScript that I'd posted in my earlier post and it worked perfectly. Thank you.

I've also been adding the Musicbrainz Work ID to my tracks and created a code to look this up from Custom4 and pull in the oldest year associated with a given Work ID. Since many of my tracks have a blank Work ID I had to add in a filter to only show those tracks where Custom4 was not empty. This is helpful to get the composition year for classical music from an existing track in my library of that same composition.

LEFT(IfNull(SQLQuery("SELECT Year AS SortField FROM Songs WHERE Custom4 = '" & Replace(oSongData.Custom4, "'", "''") & "' AND Year > 0 AND Custom4 <> '' GROUP BY Year ORDER BY SortField"), "$&"),4)

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

Post by ZvezdanD » Tue Oct 24, 2017 9:07 am

MMFrLife wrote:
TRegina wrote:Is there some expression I can insert into the Capitalize preset that will keep Irish names that begin with "McC****" intact and not turn them into "Mcc****?


I'm not sure about an expression, as the letters and positions may vary from name to name. You can just enter some of the Irish names that you
are concerned with to the "other" exceptions field (in whole; McCullers, etc.).

Are you finished with the editing of that post? :)

If you tried the preset updated in v5.1, you would know that it has Prefixes tag with Mc and O' already predefined.

Top