0

Here is a standard topic pattern which is used in mqtt.

"lights/hue/{device_name}/get/sensing"

How could I use the regular expression to format this topic pattern with a real device name.

I am not very into the regular expression, so what I would need is a function to make a topic given a device name.

for example,

pattern : "lights/hue/{device_name}/get/sensing"
input : name = 'device123'
output: "lights/hue/device123/get/sensing"

Currently I am using the lua, would someone help me?

Yu Hao
  • 115,525
  • 42
  • 225
  • 281
user824624
  • 6,275
  • 22
  • 89
  • 160

1 Answers1

2

Assuming Lua:

pattern = "lights/hue/{device_name}/get/sensing"
name = "device123"
output = string.gsub(pattern, "{device_name}", name )
print(output)

There is no need for a regular expression. Simple replacement will do the job.

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
infotoni91
  • 692
  • 3
  • 12