Lua - extract a string using patterns -


i'm starting on lua patterns.

i have string |2|34|56|1

how extract numbers string?

i can parse string manually , exclude '|' characters. i'm sure using lua patterns simpler.

how patterns in case?

if want print numbers, best method is:

str = "|2|34|56|1" str:gsub("%d+", print) 

else, if want numbers stored in table, longer approach required:

str = "|2|34|56|1" local tfinal = {} str:gsub( "%d+", function(i) table.insert(tfinal, i) end) table.foreach(tfinal, print) -- verify numbers have been stored table. 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -