lua-users home
lua-l archive

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


On 15 June 2013 03:25, Choonster TheMage <choonster.2010@gmail.com> wrote:
> On 15 June 2013 03:22,  <meino.cramer@gmx.de> wrote:
>> Hi,
>>
>> is there a way to remove leading and trailing whitespace (inluding \n
>> or \r ) from a string with lua without using lpeg or loading a C-Lib
>> for regexp?
>>
>> Thank you very much in advance for any help!
>> Best regards,
>> mcc
>>
>
> somestring = somestring:match("^%s*(.+)%s*$")

Sorry, that plus should be a minus, otherwise the capture includes the
trailing whitespace.

somestring = somestring:match("^%s*(.-)%s*$")