# Case convertion: Match \`A\` unless followed by a \`-\` \`Major\` or \`Minor\`

**URL:** https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555
**Category:** Support
**Created:** [April 30, 2024, 1:00am UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555 "2024-04-30T01:00:24Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [April 30, 2024, 1:00am UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/1 "2024-04-30T01:00:24Z")

</div>

I have been using this regular expression for case conversion with hardly any negative effects.

Regular Expression: `(?<!&|:|;|-|/|!|,|>|/|(?<![A-Z]\.[A-Z])\.|\)|\?|\+)(\s+\b(A|An|And|As|At|But|By|De|Et|For|From|In|Into|Le|Nor|Of|Off|On|Onto|Or|So|Than|The|To|Upon|Von|With)(?=\s)(?!\s[\-\(\)\[\]{}]))`

Replace with `$lower($1)`

One that does exist is that it will turn classical title that have `A Major` or `A-flat Minor` in them, for example, will be converted to `a Major` of `a-flat Minor`

So I am wondering how I can modify this regular expression so the `A` will not be matched if followed by a dash (`-`) or by the words `major` or `minor` whether they are capitalized or not. I tried to brush up on my regex skills to give it a tackle but after a bit of reading I have no clue. I would be at this for hours and hopefully it is easy for someone more versed than I in regular expressions.

---

<div class="post-metadata">

### Author: ![anon32189785](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@anon32189785](https://community.mp3tag.de/u/anon32189785)
#### Post date: [April 30, 2024, 4:20am UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/2 "2024-04-30T04:20:14Z")

</div>

> [@esumsea](#):
>
> (?\<!&|:|;|-|/|!|,|\>|/|(?\<![A-Z].[A-Z]).|)|?|+)(\s+\b(A|An|And|As|At|But|By|De|Et|For|From|In|Into|Le|Nor|Of|Off|On|Onto|Or|So|Than|The|To|Upon|Von|With)(?=\s)(?!\s[-(){}]))

Sorry, way above my paygrade but try this site to examine your regex:

> **[regex101: build, test, and debug regex](https://regex101.com/)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

---

<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: [April 30, 2024, 5:44am UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/3 "2024-04-30T05:44:56Z")

</div>

> [@esumsea](#):
>
> So I am wondering how I can modify this regular expression so the `A` will not be matched

I would not modify a complex but working regular expression but apply another action that sets the correct case for the exceptions - and that with a simple "replace" where you replace text constants with other text constants.

---

<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: [April 30, 2024, 5:49am UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/4 "2024-04-30T05:49:20Z")

</div>

With this complexity:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/2/5/25bffca83dcdcf123c487ad51f3bfd01f5f79745.png)  
I suggest to search a solution as mentionend from @ohrenkino too.

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [April 30, 2024, 1:49pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/5 "2024-04-30T13:49:26Z")

</div>

OK. I thought it would be simpler, but it seems to be too complex even for the experts here, so maybe I should not feel so bad about my skills. I will try ohrenkino's suggestion.

ohenkino, are you suggesting nesting the action in the original action where I create a replace value in the Title, ala,  
replace `a major` with 'A Major'  
replace `a Major` with 'A Major'  
replace `a minor` with 'A Minor'  
replace `a Minor` with 'A Minor'  
replace `a-` with 'A-'

---

<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: [April 30, 2024, 1:55pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/6 "2024-04-30T13:55:33Z")

</div>

> [@esumsea](#):
>
> nesting the action in the original action

If you are fond of more complex scripting expression, you may as well nest the original regular expression in a $replace() call.  
You may also use an action of the type "Guess value" in which you $replace() all the fields in which you expect the strings to appear and then separate them again.  
Or you use an action group in which you add an action of the type "Replace" for "a minor" and "a Major" and set it to be case sensitive.  
Or you add an action of the type "Format value" for the field and use $replace() in the format string.

---

<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: [April 30, 2024, 2:04pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/7 "2024-04-30T14:04:00Z")

</div>

> [@esumsea](#):
>
> replace `a-` with 'A-'

That would replace the Norwegian synth-pop band  
`a-ha`  
to  
`A-ha`

or change a song title as  
`Sing-a-Long`  
to  
`Sing-A-Long`

---

<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: [April 30, 2024, 2:16pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/8 "2024-04-30T14:16:12Z")

</div>

> [@esumsea](#):
>
> replace `a minor` with 'A Minor'  
> replace `a Minor` with 'A Minor'

You can use two more regular expressions to replace all case spellings of `a major`  
`$regexp(%TITLE%,a MaJoR,A Major,1)`  
`$regexp(%TITLE%,a mINOr,A Minor,1)`  
just write a `,1` at the end of the `$regexp` command and this will enable "ignore case" and find all variants as

`a MaJoR`  
`a major`  
`A MAJOR`  
`A MAjoR`

and so on

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

---

<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: [April 30, 2024, 3:03pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/9 "2024-04-30T15:03:49Z")

</div>

If you are looking for a solution for all variants from A minor through G-Major, you could test this one:

 ![image](https://community.mp3tag.de/uploads/default/original/3X/a/6/a6398d1439cb0fc2f92f15fbad1c94328a4448a8.png)

**Action:** Replace with regular expression  
**Field:** Whatever tag you want to modify, in this example it is the TITLE tag  
**Regular expression: (1)**  
`([a-g])[\s-](m(aj|in)or)`  
**Replace matches with: (2)**  
`$upper($1)-M$lower($3)or`

* * *

Explanation for **(1)**  
 ![image](https://community.mp3tag.de/uploads/default/original/3X/4/b/4b26f63081744f8d50225c315355a8ee1aaad768.png)

* * *

Explanation for **(2)**  
Write content of $1 in UPPERCASE (\<- The letter A through G)  
followed by a hyphen and the letter M  
Write content of $3 in lowercase (\<- either `aj` or `in`)  
followed by the letters o and r

If you don't like the hyphen in the end result, just let it out in the replacement string  
`$upper($1) M$lower($3)or`

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [April 30, 2024, 5:41pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/10 "2024-04-30T17:41:32Z")

</div>

Interesting solutions, though I may not understand them all jet. I am not sure why MaJoR or mINOr was written that way. Good point about a-ha and Sing-a-long. I guess I could just use `a-f` and `a-s` for the sharp and flats.

Another thing I am considering is just running the action where I create Titles from Work, Movement, Movement Number after the case conversion clean up action. I have set up a protocol of what to do with files to ensure they are tagged correctly before importing them. Creating Tiles from those fields is a step for classical music. since I do not run the case conversion cleanup action of the Work field, it will remain with the correct case and correct erroneous titles created by the case correction action when run.

The only caveat is that I do this for only classical and this situation may come up in a non-classical title. So perhaps adding the action on the Title filed:  
replace `a major` with 'A Major'  
replace `a Major` with 'A Major'  
replace `a minor` with 'A Minor'  
replace `a Minor` with 'A Minor'  
replace `a-f` with 'A-f'  
replace `a-s` with 'A-s'  
I rather keep things case sensitive.

This problem only occurs with the key of a, as far as I can tell, so I will just work with this closed set.

---

<div class="post-metadata">

### Author: ![esumsea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/esumsea/32/7219_2.png) [@esumsea](https://community.mp3tag.de/u/esumsea)
#### Post date: [May 1, 2024, 2:09pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/11 "2024-05-01T14:09:43Z")

</div>

To tidy up this thread, I realized I did not have to create the `a-f` and `a-s` as the A sharp and flat titles were not changed by the original reg ex expression. I thought they had but I was mistaken. It only converts the `A` to lower case if it stands alone. So that step was not needed.

I also found it better to not make the replace case sensitive in case there somehow was an `minor` or `major` that somehow escaped my case correction action. Even though that may not be possible, I don't see how it could hurt to not make the Replace action not case sensitive.

---

<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: [May 1, 2024, 2:23pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/12 "2024-05-01T14:23:12Z")

</div>

> [@esumsea](#):
>
> Even though that may not be possible, I don't see how it could hurt to not make the Replace action not case sensitive.

We don't know your music source(s). We don't know all your Actions an regular expressions that you apply to what songs.

It's really up to you IF and WHAT kind of replace Action do you use for what subset of music files.

My very personal preference is:  
Everything that could be a possible spelling mutation should be detected and then adjusted.

---

<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: [May 31, 2024, 2:23pm UTC](https://community.mp3tag.de/t/case-convertion-match-a-unless-followed-by-a-major-or-minor/64555/13 "2024-05-31T14:23:40Z")

</div>

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