Replace and Replace regexp actions issues

Hello?

I would like to set the Album name to all mp3’s files of my directory and decided to use Replace or Replace by a regexp.

  1. Use Replace : not possible to use it if Album field is currently empty because. Creating the action, “Original” has to be set to a value to be saved and cannot remain as void.
    Having a Album field equal to XX and replacing it by ZZ works fine.

  2. Use Replace by a regexp : several problems here:
    2a) using “.\*” as regexp (meaning any character zero or several times) seems to not work on empty field, replacement is not performed. Note: I added double quotes and backslash in this text to avoid italic mode creating this report, but the target is only dot+star
    2b) using “.\*” as regexp when field is not void works, but the replacement value is doubled, example: field equals XX and I would like to replace by AB, the result after replacement will be ABAB and I have no clue why, no other action selected.
    Example :
    Here is an extract of my directory. Album is set to XX

    Here is what I enter as action Replace by regexp

    So the action is stored like this:

    Expression régulière “ALBUM“: “.*” → “AB”

    And here if the result of the Action execution. Album is set to ABAB instead of just AB

    Thanks in advance.
    Brgds
    Didier
    Problem detected with v3.29 and still occurs with last v3.33.1

Could you please provide two screenshots showing your attempts with the "Replace" and "Replace with regular expression" Actions?

Also, show us a screenshot of some of your existing folders.

Without this information, it will be almost impossible to reproduce the "bug".

I think this is a basic misunderstanding: there is no table in the tag area that has a reserved space for a particular piece of information.
A field that has no data does not exist. So there is no object that can be searched and replaced.
If you want to set the contents for a field, you have to use "Format value" or any other action or converter that creates the field with contents.

For bug #2, I updated my previous post to insert screen shots before, after and the Action supposed to be executed.
To reproduce bug #1, just try to create an action Replace and try to save without any value in “Original“ field, OK is not activated until “Original“ is set.

As @ohrenkino mentioned above, you should use a “Format value” action.

Try this:

I think this is normal as the normal behaviour as any hit gets replaced with "AB".
A -> AB
B -> AB
->-> ABAB
If you use "ABC" as source you get "ABABAB".

The non-existing field yield no hit so the regular expression returns the original search string which is empty. And empty fields do not and cannot exist, therefore you do not see the intended contents.

Just a minor correction:

When using a regex replace with .* you will get a duplicate of your replacement string; this happens because there will always be 2 hits: one with the matched string ("A","B","ABC", etc.) and one with a -I'll call it for clarity- null string.

Because the use of .* literally means "find 0 or more instances of any character; with greedy search", the first match will be the "greedy search" --> the entire original string, and the second match will be the "0-length instance" immediately after the string.

@Qadddd If it were possible to have empty tag fields, your 2a) reasoning would be correct; and your 2b) reasoning logic fails to consider the second null match. If you wish to use regex, I suggest testing your formulas with an 3rd-party regex evaluator, like regex101.com, before applying to your music.
For your 2b) scenario, I suggest using .+ (1 or more instances of a character - therefore avoiding nulls), or ^.* (still matching 0+ characters, but only at the beginning of the string - which will only happen once).

@ohrenkino With the above I meant to say that if you use "ABC" as source you would still get "ABAB", same as "A", "AB", or even "ABCDEFGH".

I see no reason for this topic to be a bug report for Mp3Tag, since the regular expression engine is working correctly in this situation.

Hope this helps.

I completely agree.
Which leaves the first observation about the simple replace and that circles around empty fields.
I would assume that the mechanism could be explained as follows:
The search starts in a non-existing string and therefore, there will never be any hits. And as there are no hits these cannot be replaced.
The UI caters for that and does not allow empty strings for the original string.
Which, again, would be "works as designed, no bug".
Topic gets moved to Support.

This is THE solution, this forces the field to take the value you give if the original value is set or empty. Thanks

Nope, I try XXX as original value and the result is still ABAB.
And if I follow your logic, with X as original value, the result would be AB.
^.*$ as regexp to take the whole field from the start of field to the end of field fixed the problem. But, as mentionned above, Format value action is THE solution and it avoids regexp mind torture ;-).