# Using "Whole Word" in an Action

**URL:** https://community.mp3tag.de/t/using-whole-word-in-an-action/9433
**Category:** General Discussion
**Created:** [November 28, 2009, 5:57am UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433 "2009-11-28T05:57:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tjwhale](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/a9adbd/32.png) [@tjwhale](https://community.mp3tag.de/u/tjwhale)
#### Post date: [November 28, 2009, 5:57am UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433/1 "2009-11-28T05:57:48Z")

</div>

Hi,

I've set up some capitalization Replace rules using the 'whole word' option. When that word is bracketed by other than spaces, the action doesn't get executed. For example, my rule replaces the word uk to UK. But the string '(uk uk uk)' ends up as '(Uk UK Uk)'. Is this the expected result? Do I need to change all replaces to regular expressions in order to get the right result? I would not expect symbols to be part of words.

Terry

---

<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: [November 28, 2009, 8:33am UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433/2 "2009-11-28T08:33:06Z")

</div>

> [@tjwhale](#):
>
> ... I've set up some capitalization Replace rules using the 'whole word' option. When that word is bracketed by other than spaces, the action doesn't get executed. For example, my rule replaces the word uk to UK. But the string '(uk uk uk)' ends up as '(Uk UK Uk)'. Is this the expected result? Do I need to change all replaces to regular expressions in order to get the right result? I would not expect symbols to be part of words.  
> ...

Terry, you did not say what your capitalization rules look like and which Mp3tag features you have used to reach your goal. Please elaborate your situation.

This works for me ...  
from:  
(uk uk uk)  
to:  
(UK UK UK)

Action #1  
_Actiontype 1:_ **Case conversion**  
_Field:_ **TJWHALE**  
_Case conversion:_ **UPPER CASE**  
_Word begins after:_

.. or this ...

Action #1  
_Actiontype 5:_ **Format tag field**  
_Field:_ **TJWHALE**  
_Formatstring:_ **$replace(%TJWHALE%,'÷uk÷','÷UK÷','(uk÷','(UK÷','÷uk)','÷UK)')**  
_Note: Replace each special ÷ character with one space character._

... or this ...

Action #1  
_Actiontype 4:_ **Replace with regular expression**  
_Field:_ **TJWHALE**  
_Regular expression:_ **(?\<=[(÷])uk[÷)]**  
_Replace matches with:_ **\U$0**

[\_] Case sensitive comparison

_Note: Replace each special ÷ character with one space character._

DD.20091128.1130.CET

---

<div class="post-metadata">

### Author: ![tjwhale](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/a9adbd/32.png) [@tjwhale](https://community.mp3tag.de/u/tjwhale)
#### Post date: [November 28, 2009, 9:26pm UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433/3 "2009-11-28T21:26:42Z")

</div>

**DetlevD,**

I am currently using  
Action:REPLACE  
Field:\_FILENAME  
Original: uk  
Replace with: UK  
and checking the 'only as a word' box.

Last night I was thinking maybe something like this in a regular expression replace might be better:

Replace: ([^a-z]|^)(uk|mtv|nyc|usa)([^a-z]|$)  
With: $1$upper($2)$3  
[your \U$0 gets the same results. Does it mean uppercase the entire string?]

That way I can put all things to uppercase in one place. Well, I just tried this, and it kind of works, but not totally. I'm using a test string Of:

uk (usa nyc mtv) ( uk) nyc usa (uk uk uk) uk

The result is:

UK (USA nyc MTV) ( UK) NYC usa (UK uk UK) UK

Any thoughts on why some strings bracketed by spaces don't get uppercased?

Thanks for your help.

(update: I see why it doesn't work, the leading space for the failures is used up by the previous match. Is there a fix for this? A symbol perhaps that works like ^ but for the start of the next match-search?)

---

<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: [November 29, 2009, 4:52am UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433/4 "2009-11-29T04:52:38Z")

</div>

These expressions work for me ...

**$replace($regexp($replace(%TJWHALE%,' ',''), '(^|\(| )(uk|mtv|nyc|usa)( |\)|$)','\U$0'),'',' ') $regexp($regexp(' '%TJWHALE%' ','(?\<=[\(])(uk|mtv|nyc|usa)[\)]','\U$0'),' (.+) ','$1') $regexp(%TJWHALE%,'(^|(?\<=[\(]))(uk|mtv|nyc|usa)([\)]|$)','\U$0') $trim($replace($replace($replace(' '%TJWHALE%' ', ' ','','(','( ',')',' )'),' uk ',' UK ',' mtv ',' MTV ',' nyc ',' NYC ',' usa ',' USA '), '( ','(',' )',')','',' '))**

```
From:
"xnyc uk (usa nyc mtv) ( uk) nyc usa (uk uk uk) uk gnuk uk"
To:
"xnyc UK (USA NYC MTV) ( UK) NYC USA (UK UK UK) UK gnuk UK"

```

DD.20091129.0651.CET  
Edit. DD.20091130.0819.CET  
Edit. DD.20140128.1023.CET

---

<div class="post-metadata">

### Author: ![tjwhale](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/t/a9adbd/32.png) [@tjwhale](https://community.mp3tag.de/u/tjwhale)
#### Post date: [November 29, 2009, 7:15pm UTC](https://community.mp3tag.de/t/using-whole-word-in-an-action/9433/5 "2009-11-29T19:15:45Z")

</div>

Thanks, that works fine.

I don't want to beat this to death, but I'm still trying to figure out the expected behavior of the 'whole word' check box in the Replace action. Is it a deficiency or desired result that a string of characters is considered a word only if it's bracketed by spaces, beginning of string, or end of string? If expected, it would seem to be of limited usefulness.
