# Work with regex match as number

**URL:** https://community.mp3tag.de/t/work-with-regex-match-as-number/66156
**Category:** Support
**Created:** [October 5, 2024, 1:09am UTC](https://community.mp3tag.de/t/work-with-regex-match-as-number/66156 "2024-10-05T01:09:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mskinnernc](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/41988e/32.png) [@mskinnernc](https://community.mp3tag.de/u/mskinnernc)
#### Post date: [October 5, 2024, 1:09am UTC](https://community.mp3tag.de/t/work-with-regex-match-as-number/66156/1 "2024-10-05T01:09:29Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [October 5, 2024, 6:23am UTC](https://community.mp3tag.de/t/work-with-regex-match-as-number/66156/2 "2024-10-05T06:23:32Z")

</div>

> [@mskinnernc](#):
>
> `$regexp(%copyright%,'.*(\d{4}).*(\d{4}).*',...)`.

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

> [@mskinnernc](#):
>
> $if($geql($1,$2),$1,$2)

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

---

<div class="post-metadata">

### Author: ![mskinnernc](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/41988e/32.png) [@mskinnernc](https://community.mp3tag.de/u/mskinnernc)
#### Post date: [October 5, 2024, 9:53pm UTC](https://community.mp3tag.de/t/work-with-regex-match-as-number/66156/3 "2024-10-05T21:53:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [November 4, 2024, 9:53pm UTC](https://community.mp3tag.de/t/work-with-regex-match-as-number/66156/4 "2024-11-04T21:53:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
