Blockly text replace syntax

  • Platform information:
    • openHAB version: 4.1

Hi,
I guess I just need a smal hint.

Following Syntax is testes for ECMAScript on regex101.com
Bildschirmfoto 2024-01-04 um 17.50.59

Testing in Blocky will not match:
Bildschirmfoto 2024-01-04 um 17.51.50

pushButton = {'A': '55', 'B': '15', 'C': '45', 'D': '51', 'E': '54'};
  data = data.replaceAll('0x\\d{3}(\\d{2})',pushButton[value]); //value='B'
  console.warn(data.replaceAll('0x\\d{3}(\\d{2})',pushButton));

[WARN ] [cript.ui.transforrm_radiofrequenz433] - 0x154551

What might I do wrong?
Maybee becourse it is a BUG becauce only Stringt and no real REGEX is supported in Blockly?

It’s all JavaScript under the covers. If you want to use a regex, you need to create a regex and pass it to the first argument of replaceAll. See String.prototype.replaceAll() - JavaScript | MDN

You’ll have to use an “inline script” block to do that.

If you pass a string as the first argument, it’s going to look for that literal string to replace, not execute it as a regex.

1 Like

I missed the ECMAScript /<regex/ stuff for it :sweat_smile:
Thanks for your support. I postet a simple working Script in a new Post:

1 Like