I have some strings representing table "paths" that can be used to iterate to a value within a table, such as:
"table.subTable[2].anotherTable"
"table.subTable.otherTable.anotherTable"
"table.subTable.otherTable[3]"
[2] and [3] are indexes which might point to another table. I need to write a function that cuts off the last key/index so that the "string path" points to the previous (or "parent") table.
For example, the above strings should turn into:
"table.subTable[2]"
"table.subTable.otherTable"
"table.subTable.otherTable"
I thought this could be done by finding the last [ or . characters in the string and splitting it by using string.sub.
There might be many other ways to achieve this, such as gmatch, but I'm not sure how. Thank you in advance!