【发布时间】:2016-11-23 10:45:03
【问题描述】:
这是 mqtt 中使用的标准主题模式。
"lights/hue/{device_name}/get/sensing"
我如何使用正则表达式将这个主题模式格式化为一个真实的设备名称。
我不是很喜欢正则表达式,所以我需要一个函数来为给定设备名称的主题创建一个函数。
例如,
pattern : "lights/hue/{device_name}/get/sensing"
input : name = 'device123'
output: "lights/hue/device123/get/sensing"
目前我正在使用 lua,有人可以帮助我吗?
【问题讨论】:
-
请展示您尝试过的内容并限制为一种语言。由于您没有使用 Swift/Objective-C,因此可以删除
nsregularexpression标签。 -
你想要的输入和输出是什么?
-
示例如上。
-
var output = s.replace("{device_name}", name)- 你真的没有试过吗?
标签: lua lua-patterns