Escaping in scripting

I have several files with an artist tah of LastName, FirstName's Big Band (or Trio, etc.). Sometimes it's LastName, FirstName MiddleName's Big Band.

I want to reverse First and Last Names, leaving the 's in place.

So I tried to replace artist with $regexp(%artist%,'^(\S+),\s+(.)?(**'**s .)$',$2 $1$3)

How do I escape the single-quote before the s?

When I got tried things that resulted in a valid regexp, it put the single-quote in $2 rather than $3 like I expected. I finally came up with something that worked but I'd like to know for the future what I'm doing wrong

Also, why didn't the double-asterisks in the previous message bold the single-quote?

Removing them:

$regexp(%artist%,'^(\S+),\s+(.)?('s . )$',$2 $1$3)

You need 2 of them.: ''
See also the help on export

That's the way I got the single-quote as part of $2 instead of $3 where it should be according to the parentheses

You can try $regexp(%artist%,'^(\S+),\s+(.*)?(''''s.*)'$,$2 $1$3)

It's really a special case and I'm not arguing that this is very straight-forward :slight_smile:

By the way: Can you edit your post to enclose the format string in backticks `, e.g., `my format string` so that spaces and other special characters are preserved?

That looks like it works. It gives me something else to try. Thanks