# What is the escape character used in cumolocity?

**URL:** <https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [July 21, 2023, 10:10am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464 "2023-07-21T10:10:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriele.chiossi](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gabriele.chiossi](https://community.cumulocity.com/u/gabriele.chiossi)\
**Post date:** [July 21, 2023, 10:10am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/1 "2023-07-21T10:10:02Z")

</div>

Hello all,  
I want to use this javascript piece of code in an SVG file on a scada Widget:  
((UID\_TAG\_Number.toUpperCase()).match(/.{2}/g).join(‘:’));  
but it does not work.  
I am thinking it is the {2} parenthesis, so what is the escape character used in Cumulocity?

---

<div class="post-metadata">

**Author:** ![Pawel\_Rynarzewski1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/pawel_rynarzewski1/32/10150_2.png) [@Pawel\_Rynarzewski1](https://community.cumulocity.com/u/Pawel_Rynarzewski1)\
**Post date:** [July 26, 2023, 4:06pm UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/2 "2023-07-26T16:06:36Z")

</div>

Hi Gabriele, in your pasted code the quote characters used around `:` are wrong and cause invalid token error (it might be just due to pasting issue, but please check). Have you tried `(UID_TAG_Number.toUpperCase()).match(new RegExp('.{2}', 'g')).join(':')`? Is the expression used inside `{{ }}` interpolation or as a value for an `ng-...` attribute?

---

<div class="post-metadata">

**Author:** ![gabriele.chiossi](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gabriele.chiossi](https://community.cumulocity.com/u/gabriele.chiossi)\
**Post date:** [July 31, 2023, 7:23am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/3 "2023-07-31T07:23:02Z")

</div>

Hello Pawel,  
thank you for your answer.  
For some reason, while copying and pasting the code on this forum they changed the quotes, the correct ones are “”, I tested this. The ‘’ do not work I can confirm this.  
Also “(UID\_TAG\_Number.toUpperCase()).match(new RegExp(‘.{2}’, ‘g’)).join(‘:’)” does not work. I ended up doing a very long and complicated if statement to achieve the same thing. So even if I solved my own issue the problem IMO still stands.

---

<div class="post-metadata">

**Author:** ![Pawel\_Rynarzewski1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/pawel_rynarzewski1/32/10150_2.png) [@Pawel\_Rynarzewski1](https://community.cumulocity.com/u/Pawel_Rynarzewski1)\
**Post date:** [August 3, 2023, 10:20am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/4 "2023-08-03T10:20:52Z")

</div>

Hi Gabriele, it should work fine without `new RegExp` part:

```auto
<svg>
  <text x="30" y="30" font-family="sans-serif" font-size="18px" fill="red">
    UID_TAG_Number, before: "{{ UID_TAG_Number }}", after "{{ ((UID_TAG_Number.toUpperCase()).match('.{2}', 'g').join(':')) }}"
  </text>
</svg>

```

 ![2023-08-03_12-15](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/3/1/3163c6d2fd1709bf0b1cd2da80ec7808ec190274.png)  
(`UID_TAG_Number` is linked to `Notes` field)

---

<div class="post-metadata">

**Author:** ![gabriele.chiossi](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gabriele.chiossi](https://community.cumulocity.com/u/gabriele.chiossi)\
**Post date:** [August 3, 2023, 10:54am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/5 "2023-08-03T10:54:32Z")

</div>

How exactly should I add it under this \<svg:tspan id=“tspan321”\> because I can’t get it to work unfortunately.  
Thank you for your help.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/0/a/0a311d56fb93eb24855c6ee31df2ecf7c235cda2.png)

---

<div class="post-metadata">

**Author:** ![Pawel\_Rynarzewski1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/pawel_rynarzewski1/32/10150_2.png) [@Pawel\_Rynarzewski1](https://community.cumulocity.com/u/Pawel_Rynarzewski1)\
**Post date:** [August 4, 2023, 10:48am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/6 "2023-08-04T10:48:04Z")

</div>

Hi Gabriele, hard to say, as it works fine for me, both in an attribute and content:

 ![2023-08-04_12-37](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/8/7/873fb0784dd5059c31df8178879abd570f88fc9b.png)

with just:

```auto
<svg>
  <text x="30" y="30" font-family="sans-serif" font-size="18px" fill="red">
    UID_TAG_Number,
    before: "<tspan id="tspan{{ UID_TAG_Number }}">{{ UID_TAG_Number }}</tspan>",
    after "<tspan id="tspan{{ ((UID_TAG_Number.toUpperCase()).match('.{2}', 'g').join(':')) }}">{{ ((UID_TAG_Number.toUpperCase()).match('.{2}', 'g').join(':')) }}</tspan>"
  </text>
</svg>

```

and `lax` code sanitization option in the widget to avoid dropping `id` attribute.

Maybe the issue is you use `svg:` namespace, that’s the only difference I can see now.

Would it be possible to get a full minimal example SVG file to try to reproduce the issue on my side?

---

<div class="post-metadata">

**Author:** ![gabriele.chiossi](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gabriele.chiossi](https://community.cumulocity.com/u/gabriele.chiossi)\
**Post date:** [August 4, 2023, 12:04pm UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/8 "2023-08-04T12:04:12Z")

</div>

Yes, sure. That formula will have to go under \<svg:tspan id=“tspan321”\> and go substitute the whole and complicated if statement that is under the mentioned tag.

```auto
(https://fs-lt.tttech.com/s/6jK9Y7J28CqKj4E)

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Pawel\_Rynarzewski1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/pawel_rynarzewski1/32/10150_2.png) [@Pawel\_Rynarzewski1](https://community.cumulocity.com/u/Pawel_Rynarzewski1)\
**Post date:** [August 4, 2023, 8:54pm UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/9 "2023-08-04T20:54:56Z")

</div>

Thanks, I see the issue now and my previous suggestions were not correct. However, it’s not the matter of escaping some characters. The problem is that AngularJS expressions do not support regular expressions (see e.g. [How can I use that regex in angularJs expression? - Stack Overflow](https://stackoverflow.com/questions/54464396/how-can-i-use-that-regex-in-angularjs-expression)), so - as we can only modify the svg - I thought about passing the expression as string to `match`, but it doesn’t support `g` flag. `matchAll` can take the expression and match it globally, but it returns an iterator. One way of getting values from iterator is to use spread operator, but again it’s not supported in ng1 templates. Another one is `Array.from` but it’s not directly available, so you’d need a hack:

```auto
{{ []. __proto__.constructor.from(UID_TAG_Number.toUpperCase().matchAll('.{2}')).join(':') }}

```

then the tag number is upper cased and split into groups of 2 separated with colon:

 ![2023-08-04_22-48](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/d/5/d5f2ac6ea972647538fccf73a43693ec7be30c53.png)

---

<div class="post-metadata">

**Author:** ![gabriele.chiossi](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gabriele.chiossi](https://community.cumulocity.com/u/gabriele.chiossi)\
**Post date:** [August 29, 2023, 6:57am UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/10 "2023-08-29T06:57:25Z")

</div>

> [@Pawel\_Rynarzewski1](#):
>
> `{{ []. __proto__.constructor.from(UID_TAG_Number.toUpperCase().matchAll('.{2}')).join(':') }}`

Hello Pawel,  
thank you for getting back to me, I tried the formula that you said but the result that you have on your side it is not what I see on my side. Do you have any other ideas?

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/7/3/7358902cf56d47035e2f6f3493ada101e01f5081.png)

---

<div class="post-metadata">

**Author:** ![Pawel\_Rynarzewski1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/pawel_rynarzewski1/32/10150_2.png) [@Pawel\_Rynarzewski1](https://community.cumulocity.com/u/Pawel_Rynarzewski1)\
**Post date:** [September 20, 2023, 1:45pm UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/11 "2023-09-20T13:45:49Z")

</div>

Hi Gabriele, sorry for delay. Looks like the expression has been sanitized. Have you tried with `none` option in “Select code sanitization option” in the widget settings?  
 ![Peek 2023-09-20 15-43](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/0/e/0ec529228fb93f65a75f8edb131cd04be0ab3afc.gif)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [March 18, 2024, 1:46pm UTC](https://community.cumulocity.com/t/what-is-the-escape-character-used-in-cumolocity/7464/12 "2024-03-18T13:46:23Z")

</div>

Closed on March 18, 2024, 1:46pm UTC

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