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
  • 119,891
  • 44
  • 235
  • 294
user824624
  • 7,077
  • 27
  • 106
  • 183

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
  • 607,720
  • 39
  • 448
  • 563
infotoni91
  • 722
  • 3
  • 13