【发布时间】:2018-07-22 19:12:21
【问题描述】:
我有 2 个字符串:
$ip = [{"ip":"127.0.0.1"}]
$port = [{"port":"80"}]
我只想为第一个保留$ip = 127.0.0.1,为第二个保留$port = 80。我应该如何使用正则表达式?
/////////更新//////////
我这样做了,它有效,但写得不好:
ip = string.match(respIp.body, "%:(.*)");
ip = string.match(ip, "(.*)%}");
ip = string.sub(ip, 2, string.len(ip)-1);
port = string.match(respPort.body, "%:(.*)");
port = string.match(port, "(.*)%}");
port = string.sub(port, 2, string.len(port)-1);
【问题讨论】:
-
我对nginx一无所知,但我会用正则表达式
replace_filter '[[\]{}"]' '' g;替换 -
@Leyffda 我更新了我的帖子。如果您有更好地重写的想法,我很感兴趣。
-
_, _, ip2 = string.find(ip, '"ip":"([^"]+)')怎么样? -
两个字符串的一个解决方案:
s:match('"([%d.]+)"') -
$ip =是字符串的一部分吗?