lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This one has got me stuck for the moment, can anyone come up with an elegant solution for this without needing external library please.

I have a long string of text that i need to split into sentences, here is a sort of working attempt

 local text = "This is one sentence. This is another but with a number in it like 0.47 need to ignore it. This is the third. Fourth sentence"

local sentences = {}
for i in string.gmatch(text,  "[^%.]+" ) do
sentences[#sentences+1] = i
 end

for i = 1, #sentences do
print(i, sentences[i])
end

Of course I had forgotten about not splitting on decimal points in numbers.  How can I adapt this to ignore the full stop character if surrounded by numbers?

Thanks for any solutions.

Geoff


Virus-free. www.avast.com