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.

