# How to use $if function in Replace with regular expression?

**URL:** https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241
**Category:** Support
**Created:** [December 26, 2006, 6:05pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241 "2006-12-26T18:05:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![krtek](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krtek](https://community.mp3tag.de/u/krtek)
#### Post date: [December 26, 2006, 6:05pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/1 "2006-12-26T18:05:43Z")

</div>

I want to transform some Russian tags to latin characters and changing codepage does not work correctly (it gives rubbish). So I want to do it manually with regexes. I want the action to be sensitive for that if the tag is uppercase or if only first letters of words are capitalised. The problem is that sometimes you get two (or three) latin letters for one cyrylic letter.  
I want the script to use uppercase latin letters if the whole word is uppercase and to capitalise only first letter if the original word has only the first letter capitalised. (e.g. [on lattin letters - suppose I want to replace every P with Po]: PLACE -\> POLACE, but Place -\> Polace).  
I don't want to change capitalisation of original tags (cause there are names and other things that should not be lowercased) so replacing letters normally and using Capitalise or Uppercace action does'nt satisfy me.

I tried such regex:  
Regular expression: ([A-Z])?P([A-Z])?  
Replace with: $if($or($1,$2),$1PO$2,$1Po$2)

I wonder why it doesn't work and how to achive my goal.

BTW it is a mystery to me how to use the $if function? Does it works correctly only on tags fields and not on backrefferences ($1,$2)?

Thanks a lot if anyone can help me!

---

<div class="post-metadata">

### Author: ![Sebastian\_Mares](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sebastian_mares/32/9285_2.png) [@Sebastian\_Mares](https://community.mp3tag.de/u/Sebastian_Mares)
#### Post date: [December 26, 2006, 6:53pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/2 "2006-12-26T18:53:11Z")

</div>

You cannot use scripting functions with RegEx replace action types. You might want to use a Format values action together with the $regexp() function that is documented in the [help](https://docs.mp3tag.de/scripting).

---

<div class="post-metadata">

### Author: ![krtek](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krtek](https://community.mp3tag.de/u/krtek)
#### Post date: [December 26, 2006, 7:35pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/3 "2006-12-26T19:35:59Z")

</div>

But it won't work for all tag fields... And specifing 60-100 actions multiplied by the number of tag fields is definitely not what I am looking for...

---

<div class="post-metadata">

### Author: ![DetlevD](https://community.mp3tag.de/user_avatar/community.mp3tag.de/detlevd/32/123_2.png) [@DetlevD](https://community.mp3tag.de/u/DetlevD)
#### Post date: [December 27, 2006, 9:20am UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/4 "2006-12-27T09:20:55Z")

</div>

May you show us your translation table?  
From Cyrilic character to Latin character resp. string:  
...  
P =\> PO  
p =\> po  
...  
and so on.  
I am sure there might be some way to solve the problem from within Mp3tag.

DD.20061227.1120

---

<div class="post-metadata">

### Author: ![krtek](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krtek](https://community.mp3tag.de/u/krtek)
#### Post date: [December 27, 2006, 4:38pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/5 "2006-12-27T16:38:05Z")

</div>

I have done it step by step and it works, but it isn't elegant.

First - transcription table:

А -\> A  
Б -\> B  
В -\> V  
Г -\> G  
Д -\> D  
Е -\> E (but after И -\> YE; ИЕ = IYE)  
Ё -\> YO  
Ж -\> ZH  
З -\> Z  
И -\> I  
Й -\> Y (but after Ы -\> J; ЫЙ = YJ)  
К -\> K  
Л -\> L  
М -\> M  
Н -\> N  
О -\> O  
П -\> P  
Р -\> R  
С -\> S  
Т -\> T  
У -\> U  
Ф -\> F  
Х -\> H  
Ц -\> C  
Ч -\> CH  
Ш -\> SH  
Щ -\> SCH  
Ъ -\> '  
Ы -\> Y  
Ь -\> '  
Э -\> E  
Ю -\> YU  
Я -\> YA

So I set the replace(or replace with regex) action for every single letter (in alphabetical order) for lowercase and uppercase seperately.

For letters that are replaced with only one-letter it looks like that (field: \_ALL, casesensitive):

1. oryginally: С  
replace with: S

2. oryginally: с  
replace with: s

For letters that are replaced with more than one letter I had to set five actions per one Russian letter, e.g. (field: \_ALL, casesensitive):

1. regex: ([A-Z]|[А-Я])Ж([A-Z]|[А-Я])  
replace with: $1ZH$2

2. regex: (^)Ж([A-Z]|[А-Я])|(\s)Ж([A-Z]|[А-Я])  
replace with: $1ZH$2

3. regex: ([A-Z]|[А-Я])Ж(\s)|([A-Z]|[А-Я])Ж$  
replace with: $1ZH$2

4. regex: Ж  
replace with: Zh

5. regex: ж  
replace with: zh

For Е and Й - something like:  
([iIИи])E replace with $1YE  
([^iIИи])E replace with $1E  
(four-five versions to match every lower/uppercase situation)

And it works, but looks horrible (91 actions). And is very hard to maintain. With conditionals it would look (and be) much shorter, easier, better...

BTW: how to save my bunch of actions in some safe place (e.g. on CD)  
There are Standard, CD-R, and CaseConversion actions (whit .mta extention) in program folder (Mp3tag\data\actions), but I can't find any of my personal sets of actions there (and anywhere)...  
Where are they stored?

---

<div class="post-metadata">

### Author: ![Sebastian\_Mares](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sebastian_mares/32/9285_2.png) [@Sebastian\_Mares](https://community.mp3tag.de/u/Sebastian_Mares)
#### Post date: [December 27, 2006, 7:26pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/6 "2006-12-27T19:26:03Z")

</div>

> [@krtek](#):
>
> BTW: how to save my bunch of actions in some safe place (e.g. on CD)  
> There are Standard, CD-R, and CaseConversion actions (whit .mta extention) in program folder (Mp3tag\data\actions), but I can't find any of my personal sets of actions there (and anywhere)...  
> Where are they stored?

They are stored in the %APPDATA%\Mp3tag\data\actions folder (%APPDATA% is a Windows variable and can be entered as-is in Windows Explorer - it points to X:\Documents and Settings\User\Application Data, where X is the system drive - usually C - and User is the name of the user account).

So, why don't you like the $regexp() function? You can use it together with $if() in a Format values action.

---

<div class="post-metadata">

### Author: ![krtek](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krtek](https://community.mp3tag.de/u/krtek)
#### Post date: [December 27, 2006, 7:58pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/7 "2006-12-27T19:58:58Z")

</div>

Thanks. I have found my actions:-)  
As I already explained, when you use Format Value, you can't specify field as \_ALL (or I can't do it).  
So I could have specify every action for EVERY used field. Result - 100 actions (or more).  
That's not what I am looking for.

---

<div class="post-metadata">

### Author: ![Sebastian\_Mares](https://community.mp3tag.de/user_avatar/community.mp3tag.de/sebastian_mares/32/9285_2.png) [@Sebastian\_Mares](https://community.mp3tag.de/u/Sebastian_Mares)
#### Post date: [December 27, 2006, 9:20pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/8 "2006-12-27T21:20:03Z")

</div>

Ah, now I understood, sorry. Well, yeah, you've got a point. 🙂

---

<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: [February 9, 2026, 12:20pm UTC](https://community.mp3tag.de/t/how-to-use-if-function-in-replace-with-regular-expression/4241/9 "2026-02-09T12:20:04Z")

</div>


