# Troubleshooting an Existing Regex

**URL:** <https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263>\
**Category:** Support\
**Created:** [June 14, 2023, 10:29am UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263 "2023-06-14T10:29:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)\
**Post date:** [June 14, 2023, 10:29am UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/1 "2023-06-14T10:29:30Z")

</div>

Hello Everyone,

[Referencing this topic dd. Oct '17.](https://community.mp3tag.de/t/expression-needed-to-retain-one-word-in-a-sentence/19445)

I apply the following expression in Action Type \> Format Value:

`$regexp(%ARTIST%,'^.*\s([\w-]+)$','$1')`

in order to retain the last word, in a given sentence. In this case the Artist Field where I wish to retain the artist's surname.

Would you please show me where I have it wrong, because it fails to apply as it should to hyphenated last words, such as this one, which remains unaffected:

_Camille Saint‐Saëns_

Thank you.

---

<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:** [June 14, 2023, 10:48am UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/2 "2023-06-14T10:48:10Z")

</div>

> [@ragtag](#):
>
> Camille Saint‐Saëns  
> ...  
> because it fails to apply as it should to hyphenated last words, such as this one, which remains unaffected

That's easy to explain:  
Your character between Saint and Saëns is not the same as the character after the `\w` in your regex.  
If you try it with  
$regexp(%ARTIST%,'^.\*\s([**\w-‐**]+)$','$1')  
`$regexp(%ARTIST%,'^.*\s([\w-‐]+)$','$1')` \<--- both of the dashes looking equal, but they are not!  
it should work.

* * *

**Update some hours later:**  
In Mp3tag the above format string does NOT work, please have look [here](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/4)

* * *

The differences in detail:  
The character after `\w` in your original regex is a  
`U+002D : HYPHEN-MINUS {hyphen, dash; minus sign}`  
The character between Saint and Saëns in the artist name is a  
`U+2010 : HYPHEN`  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/2/2c3b4769892133a028c3c7210bea27fcaffb30d5.png)

You may also encounter one of these other variants of "dashes" (looking very similar, but not equal):

> **[Find all Unicode Characters from Hieroglyphs to Dingbats – Unicode Compart](https://www.compart.com/en/unicode/category/Pd)**
>
> All Unicode Symbols with Names and Descriptions on One Page

---

<div class="post-metadata">

**Author:** ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)\
**Post date:** [June 14, 2023, 12:53pm UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/3 "2023-06-14T12:53:41Z")

</div>

![image](https://community.mp3tag.de/uploads/default/original/2X/c/c86f91ef2aa533e834373683246c7d525f92b5e8.png)

Thank you, @LyricsLover, I certainly was not even aware of these variations. I applied your expression as shown in the screenshot above, and received this error message in the Artist field:

_REGEXP ERROR: Regular expression_  
_Invalid range end in character class The error occurred while parsing the regular expression: '^._\s([\w-\>\>\>HERE\>\>\>]+)$'.\*

I then re-applied it like this — using only the slightly elevated hyphen in your expression — and it worked just fine:

![image](https://community.mp3tag.de/uploads/default/original/2X/6/6fa18292a91e228394f0c4618bd83f754722eadc.png)

If at all possible, is it not feasible to construct an expression that combines the most commonly used hyphens, since these are not easy to tell apart?

---

<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:** [June 14, 2023, 1:03pm UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/4 "2023-06-14T13:03:30Z")

</div>

> [@ragtag](#):
>
> received this error message in the Artist field

You are right, sorry for the confusion.  
For a Mp3tag regular expression you have to escape the minus dash (after `\w`) with a backslash, otherwise the minus will be interpreted in a unwanted way.  
Please try it with this format string:  
`$regexp(%ARTIST%,'^.*\s([\w\-‐]+)$','$1')`  
 ![image](https://community.mp3tag.de/uploads/default/original/2X/2/2b090013bff23941cd198ea279271a8e63dc8bdb.png)

> [@ragtag](#):
>
> If at all possible, is it not feasible to construct an expression that combines the most commonly used hyphens, since these are not easy to tell apart?

Unfortunately, I'm not aware that an easy way exists for this. You would have to enter all the various dash variants in your regular expression.

---

<div class="post-metadata">

**Author:** ![ragtag](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ragtag/32/13146_2.png) [@ragtag](https://community.mp3tag.de/u/ragtag)\
**Post date:** [June 14, 2023, 1:16pm UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/5 "2023-06-14T13:16:22Z")

</div>

> [@LyricsLover](#):
>
> `$regexp(%ARTIST%,'^.*\s([\w\-‐]+)$','$1')`

Thank you, this one worked pefectly.

---

<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:** [July 14, 2023, 1:16pm UTC](https://community.mp3tag.de/t/troubleshooting-an-existing-regex/61263/6 "2023-07-14T13:16:53Z")

</div>

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