dimanche 23 juin 2019

Split string by dot lua

I'm trying to split a string by a single dot, yet retain double(and more) dots.

My approach is like this,which works only with double dots:

local s = "some string.. with several dots, added....more dots.another line inserted."; for line in s:gsub('%.%.','#&'):gmatch('[^%.]+') do print(line:gsub('#&','..')); end

Another approach was like this

print(s:match('([^%.]+[%.]*[^%.]+)'))

which halts after the next sequence of dots, so it does not suit properly.

How could I accomplish this in a pattern matching?

Aucun commentaire:

Enregistrer un commentaire