Escaping characters?

Using QGIS 3.44.8 and QField 4.1.1: I need to store the characters { and } in a field “tilleggssymbol” set as Value relation widget where multi selections are allowed, i.e. several characters may be selected and saved in “tilleggssymbol”. Among these characters are { and }. Is it possible to escape these characters? I have tried \{ and \} without any luck. The closest I’ve come is to use ‘{’ and ‘}’, but only the ‘’ and ‘’ are shown as label? In the example below, I want 2a!{}@ to appear. In the layer, {!,‘{’,‘}’,@} is saved. I would prefer {!,{,},@}, but that may not be possible as long {} are used to “encapsulate” the attribute values?

Does using a single quote before the character work as escape?

No, “{ and “{“ do not work.

Does are double quotes are they? Or is the editor here messing things up? Could you try a single quote?
'{

I have tried quite a few alternatives involving single ‘ and double “ with and without escaping character \. Single starting and ending quote ‘{‘ is the closest I have come saving the { and } in the streng, see screenshot above. However, the label is only showing ‘‘‘‘ missing the { and the }, see screenshot above.

Hmm, there are multiple things going on, so I think we could use a better understanding of this setup.
What is the expression you use to fill the field tilleggssymbol?
And what is the field type of tilleggssymbol?
And what is the expression you use to create the label?

Or even better, could you share this project including just the relevant data?

Solved! Thanks for your time and effort, Jeroen Groene Bij
I had a closer look into the layer properties and found out the problem wasn’t the { and }. They may be used directly as { and }, no single’ or double ‘‘ is needed. The “problem” (error) was in the label-expression REPLACING the {“,} wrongly.
ALL { and } where replaced with ‘‘ (“nothing”), but only starting { and ending } should be replaced.
Example #}! is saved as {“#”,”}”,”!”}. However the label should appear as #}!. Thus the saved string need to be manipulated when used as label. The correct expression did the trick:
coalesce(regexp_replace(regexp_replace(“tillegg1”, ‘^\{(.*?)\}$’, ‘\1’), ‘[",]’, ‘’),‘’)
(This afternoon it was decided that character { is obsolete, and therefore only } is included in the expression).

2 Likes