Reputation: 107
I have a rest URL as a string --> rest/dashboard/person/hari/categrory/savingaccount/type/withdraw
In this I have to get the value between person and category && value between categrory and type. Because those value will dynamically change
rest/dashboard/person/{{}}/categrory/{{}}/type/withdraw
I tried with string.gsub(mystring, "([%w]+%/)([%w%d]+)")
. But it seems it is not the correct wast to do it
Please help
Upvotes: 2
Views: 1361
Reputation: 72312
string.match
with captures is the right tool for the job.
Try this:
s="rest/dashboard/person/hari/category/savingaccount/type/withdraw"
print(s:match("/person/(.-)/category/(.-)/type/"))
Upvotes: 4