Work with regex match as number

Problem: I have a copyright statement, containing two years. (eg 2001 and 2002). I want to set the YEAR tag to the latest year.
I.e. format value YEAR.
I get the two years: $regexp(%copyright%,'.*(\d{4}).*(\d{4}).*',...).
Problem is the replacement term, no matter how I compare the terms, the comparison returns false, and it returns the second term.
I have tried every combination of:
Comparison functions: $if($geql($1,$2),$1,$2), same with $if($leql); $ifgreater($1,$2,$1,$2), $less; $grtr.
As to the params $1 and $2, I have tried: $1/$2; $num($1,), $add(0,$1), $sub($1,$2), $fmtNum($1), $num($trim($1)), and even $fmtDuration.
No matter what I use, the comparison always returns false.
How do I do this?

This is missing the output part.
If you want to compare 2 values you first extract each value with the regular expression and then compare them.
so in

the $1 should be replaced with
$regexp(%copyright%,'.*(\d{4}).*(\d{4}).*',$1)
and
$2 with
$regexp(%copyright%,'.*(\d{4}).*(\d{4}).*',$2)
You can test the whole expression in Convert>Tag-Tag

Thanks! So, in short, instead of using condition inside regex expression, use regex expression inside condition.

Also, thanks for the testing tip! Makes life a lot easier.