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


#1

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!


#2

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.


#3

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...


#4

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


#5

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?


#6

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.


#7

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.


#8

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