# $regexp confusion - problem with escaping?

**URL:** <https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652>\
**Category:** Support\
**Created:** [January 2, 2018, 9:48am UTC](https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652 "2018-01-02T09:48:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BushAl](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@BushAl](https://community.mp3tag.de/u/BushAl)\
**Post date:** [January 2, 2018, 9:48am UTC](https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652/1 "2018-01-02T09:48:04Z")

</div>

Hi and thanks for a great program, which i just discovered. It seems to do almost anything.

However i am obviously too thick to understand exactly what needs escaping where.

I want to use the artist tag (which contains multiple artists) to generate the artistsort tag.  
I need to handle three cases :-  
either a title start in in The, Les etc which should have the , The added at the end  
or anything containing a set of names indicating an orchestra which doesnt start as above (symphony, orchestra etc etc) which should be copied as is  
or anything else is assumed to be a name to be reversed (John Paul Jones =\> Jones, John Paul)

It seems i can do all of the three via a replace with regular expression but when i try to combine them into a scripted expression i cant get it to work despite reading a number of posts on escaping and trying a lot of variations over a couple of hours. I therefore throw myself on your mercy..

Just looking at the first case the action  
Format Value 'ARTISTSORT': $meta(artist,0)  
Replace with Regular Expresion 'ARTISTSORT': "^(the|el|los|la|las|le|les)\s(.\*)" =\>"$2, $1"

works and replaces "Les Arts Florissants" with "Arts Florissants, Les"

however when I put this in a script  
Format Value 'ARTISTSORT': $regexp($meta(artist,0),'^(the|el|los|la|las|le|les)\s(.\*)','$2, $1')  
I always get "Les Arts Florissants" regardless of using $1 $2 or both.

So please show me what needs to be done to make this work.

for name I would use $regexp($meta(artist,0),'(._) (._)', '$2, $1') which does work

Logically as they are quite similar i need to escape the ^ | or replace the \s with blank, but i think i have tried all combinations without success.

Thanks for any help offered

---

<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:** [January 2, 2018, 10:00am UTC](https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652/2 "2018-01-02T10:00:02Z")

</div>

the $regexp() is case-sensitive. "the" does not match "The"

---

<div class="post-metadata">

**Author:** ![BushAl](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@BushAl](https://community.mp3tag.de/u/BushAl)\
**Post date:** [January 2, 2018, 7:24pm UTC](https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652/3 "2018-01-02T19:24:30Z")

</div>

My specialty - ignoring the obvious - Thanks very much

---

<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:27pm UTC](https://community.mp3tag.de/t/regexp-confusion-problem-with-escaping/19652/4 "2026-02-09T12:27:09Z")

</div>


