# $if statement not working

**URL:** https://community.mp3tag.de/t/if-statement-not-working/65709
**Category:** Support
**Created:** [August 23, 2024, 4:32pm UTC](https://community.mp3tag.de/t/if-statement-not-working/65709 "2024-08-23T16:32:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![directsounds](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@directsounds](https://community.mp3tag.de/u/directsounds)
#### Post date: [August 23, 2024, 4:32pm UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/1 "2024-08-23T16:32:43Z")

</div>

Does anyone know what I'm doing wrong?

`$if2($regexp(%title%,'(.*?)(\(|\[)(feat|ft)\.\s(.*?)\s*(\)|\])',%artist%; $4),%artist%)`

Why does this copy the title to the artist tag if there is no feat. or ft. tag in the title? Should this not keep the artist's information as it is? It works perfectly in adding the artist when I need it to but I would prefer to just run the action on all songs rather than manually selecting the songs with feat.

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [August 23, 2024, 4:38pm UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/2 "2024-08-23T16:38:19Z")

</div>

For a better understanding of the regular expression itself:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/7/c/7c1b9c19bc129017ba9ee85569b739a36b974364.png)

Where did you get this regular expression? Did you make it yourself?

From the [help documentation](https://docs.mp3tag.de/scripting/#boolean-functions):  
`$if2(x,y)` if x is true, x is returned, otherwise y.

---

<div class="post-metadata">

### Author: ![directsounds](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@directsounds](https://community.mp3tag.de/u/directsounds)
#### Post date: [August 23, 2024, 5:30pm UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/3 "2024-08-23T17:30:19Z")

</div>

Yep, I made the regex for the artist's information, I just looked at some of the logic and applied it to the examples I had for different titles. I usually test the regex on an online checker to see if it works the way I want, then convert it to use within mp3tag.

---

<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: [August 24, 2024, 6:19am UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/4 "2024-08-24T06:19:26Z")

</div>

> [@directsounds](#):
>
> Why does this copy the title to the artist tag if there is no feat. or ft. tag in the title?

If no match is found in the expression, the whole search string gets returned.  
$If2() produces the "x" part as %artist% returns valid data.

> [@directsounds](#):
>
> I usually test the regex on an online checker

You can test a format string in Convert\>Tag-Tag - which takes care of MP3tag's regular expression flavour.

---

<div class="post-metadata">

### Author: ![directsounds](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@directsounds](https://community.mp3tag.de/u/directsounds)
#### Post date: [August 25, 2024, 9:26pm UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/5 "2024-08-25T21:26:21Z")

</div>

Thanks, I've never used tag-tag before but I was able to resolve this by using `$if($eql($regexp(%title%,'.*(\(|\[)(feat|Feat|ft|Ft)(\.\s)(.+)(\)|\]).*',1),1),$regexp(%title%,'(.+)?(\(|\[)(feat|Feat|ft|Ft)(\.\s)(.+)(\)|\])(.+)?',%artist%; $5,),%artist%)`

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [August 26, 2024, 6:15am UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/6 "2024-08-26T06:15:09Z")

</div>

The two regular expressions now looks like this:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/b/8/b8dc89465d8b585a36e8dcc25973fe0e7983a4ed.png)  
and  
 ![image](https://community.mp3tag.de/uploads/default/original/3X/5/a/5aed44b7f6ea4ecc90cb8a7b858c0e5e6a8f759b.png)

---

<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: [September 25, 2024, 6:15am UTC](https://community.mp3tag.de/t/if-statement-not-working/65709/7 "2024-09-25T06:15:12Z")

</div>

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