how can I extract a few words separated by symbols in a string so that nothing is extracted if the symbols change? for example I wrote this code:
function split(str)
result = {};
for match in string.gmatch(str, "[^%<%|:%,%FS:%>,%s]+" ) do
table.insert(result, match);
end
return result
end
--------------------------Example--------------------------------------------
str = "<busy|MPos:-750.222,900.853,1450.808|FS:2,10>"
my_status={}
status=split(str)
for key, value in pairs(status) do
table.insert(my_status,value)
end
print(my_status[1]) --
print(my_status[2]) --
print(my_status[3]) --
print(my_status[4]) --
print(my_status[5]) --
print(my_status[6]) --
print(my_status[7]) --
output :
busy
MPos
-750.222
900.853
1450.808
2
10
This code works fine, but if the characters and text in the str string change, the extraction is still done, which I do not want to be.
If the string change to str = "Hello stack overFlow" --- out put:
Hello
stack
over
low
nil
nil
nil
In other words, I only want to extract if the string is in this format :"<busy|MPos:-750.222,900.853,1450.808|FS:2,10>"
Thanks for any answers
string.gmatch(str, "[%+%-%.%w%d]+" )- Mike V.