Simple way to abort action if regex does not match?

I'm working on an action to extract the year from the title.

Format value:
Field:
YEAR
Format string:

$regexp(%title%,^.*\D((?:(19|20))\d{2})(?:\D.*|$),$1)

Which does a solid job of only matching actual years.

However, when the regex does not match (no year in the title), it replaces %YEAR% with the content of %TITLE%, which is obviously unwanted.

I do know a workaround for this.
By nesting $if and $neql like this, first the result of the regex is compared to %TITLE% and only if it differs from %TITLE%, is %YEAR% replaced with the match.

Here's the workaround, which is very wordy and a total mess to write (I had to correct 4 typos while being a consistent typer).

$if($neql($regexp(%title%,^.*\D((?:(19|20))\d{2})(?:\D.*|$),$1),%title%),$regexp(%title%,^.*\D((?:(19|20))\d{2})(?:\D.*|$),$1),%year%)

Is there an easier way I'm not aware of to say:
Replace X with the match of the regex, ONLY if a match was found, otherwise do nothing?

I know that returning the full string when no match was found is the default behavior in some programming languages, but in this case it's more often a hindrance than useful imho.

I you do not want to get the whole TITLE into YEAR, then you could use the
format string: $num($regexp(%title%,^.*\D((?:(19|20))\d{2})(?:\D.*|$),$1),1)
which should return 0 if the result is a text.
This does not work for titles like e.g.
1999 - Prince
1984 - Eurythmics
but in general, the regular expressions in MP3tag return the source string if no match is found so that no data is lost.

Good idea, but replacing the YEAR with 0 is unwanted as well.

I just noticed that my regex did not match these.

But that can be accounted for by changing the regex to:

(?:^.*\D|^)((?:(?:19|20))\d{2})(?:\D.*$|$)

Which makes the full code even longer (since the regex occurs twice):

$if($neql($regexp(%title%,(?:^.*\D|^)((?:(?:19|20))\d{2})(?:\D.*$|$),$1),%title%),$regexp(%title%,(?:^.*\D|^)((?:(?:19|20))\d{2})(?:\D.*$|$),$1),%year%)

I also tried using $if2(x,y) like this:
$if2($regexp(%title%,(?:^.*\D|^)((?:(?:19|20))\d{2})(?:\D.*$|$),$1),%year%)
but since the regular expression always returns a value, y is never used.

$regexp(x,e,r,c)
As the default behavior that's sensible. I just wish there was a 5th parameter to toggle the behavior from returning x when no match is found to instead return False or simply abort when there is no match. In the case of returning False, the $if2(x,y) method, which is short, should work.

So perhaps you should construct a filter that returns only the files that you wish your action to process. You could start with something as simple as

TITLE MATCHES "19|20"

and then refine the RegEx as needed.

I have a couple of actions where I only want to copy part of one field to another field, but only if a match was found.
With my (quite wordy and hard to maintain) workaround I can do just that.

Manually filtering the files before using each action defeats the purpose of my actions which I always aim to make as "safe" to use as possible. As in: Even if you run them accidentally, they should not be able to do much harm, which also allows me to use many of them at the same time without having to worry (I still check all results).

The only reason for this thread was to see if I am overlooking an easier (or shorter) way to achieve that functionality.
And sadly there does not seem to be one at this time.
If I manage to find one down the road I'll update this thread. Thanks for your input tho!