Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string by dot lua, yet retain double and triple dots

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?

like image 856
das Avatar asked Mar 01 '26 11:03

das


1 Answers

local s = 'some string.. with several dots, added....more dots.another line inserted.'
for line in s:gsub("%f[.]%.%f[^.]", "\0"):gmatch"%Z+" do 
   print(line) 
end
like image 100
Egor Skriptunoff Avatar answered Mar 04 '26 10:03

Egor Skriptunoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!