How Do I Escape Special Characters in an Expression?


#1

1) Give a description of the problem

Special characters causing expressions to be processed incorrectly. Specifically the [ and ] characters.

I have this expression:

'[b, green | {([sonosPlayer:status] == 'playing' ? 'Playing' : ([sonosPlayer:status] == 'stopped' ? 'Stopped' : ([sonosPlayer:status] == 'paused' ? 'Paused' : [sonosPlayer:status])))}]\n[b, green | Track:][b, dodgerblue | {[sonosPlayer:trackDescription]}]\n[b, green | Volume:][b, dodgerblue | {[sonosPlayer:level]}]'

trackDescription can contain special characters like [ and ] and these are processed as brackets by the expression.

2) What is the expected behavior?

I want to be able to ‘escape’ these characters so they are read as a string. How do I do that?

3) What is happening/not happening?

Example result of above when [ or ] are in trackDescription:

Example with no brackets in the trackDescription:


#2

Try using

replace([sonosPlayer:trackDescription],"\\[","\\\\[", "\\]", "\\\\]")

(this is what would work in an expression - you might have to play with the “\” a little incase the results don’t work as expected in your case.


#3

Thanks. I’ll give that a try and report back.

UPDATE: I have been trying … struggling to make it work so far. Will keep trying.