我有一个休息网址作为字符串 -->rest/dashboard/person/hari/categrory/savingaccount/type/withdraw
在这方面,我必须获得人与类别之间的值&&分类和类型之间的价值。因为这些值会动态变化
rest/dashboard/person/{{}}/categrory/{{}}/type/withdrawal
我试过string.gsub(mystring, "([%w]+%/)([%w%d]+)")
.但似乎这样做不是正确的浪费
请帮忙
带有捕获功能的string.match
是完成这项工作的正确工具。 试试这个:
s="rest/dashboard/person/hari/category/savingaccount/type/withdraw"
print(s:match("/person/(.-)/category/(.-)/type/"))
您可以按照建议使用惰性点.-
或否定字符类[^/]+
s="rest/dashboard/person/hari/category/savingaccount/type/withdraw"
print(s:match("person/([^/]+)/category/"))
print(s:match("category/([^/]+)/type/"))
演示