451 posts
Location
The left part of this post
Posted 29 March 2013 - 02:40 PM
I want to know how do i obtain the text inside brackets
ex: [lol] will return lol and [[fdfsdfsdf]] will return [fdfsdfsdf]
1688 posts
Location
'MURICA
Posted 29 March 2013 - 03:06 PM
Use string.match.
local matchstr = '%[(.-%]*)%]'
local text
text = string.match('[some brackets]', matchstr)
print(text) --> some brackets
text = string.match('[[some more brackets]]', matchstr)
print(text) --> [some more brackets]
2088 posts
Location
South Africa
Posted 30 March 2013 - 01:04 AM
pattern of
'%[(.-)%]'
works too. Curious to know if there's a difference though.
1688 posts
Location
'MURICA
Posted 30 March 2013 - 05:24 AM
I actually tested both in my lua prompt on my computer before making my post up there, and the matchstring you suggested stops capturing the string after the first right bracket. In the case of "[[some more brackets]]", it would capture "[some more brackets".
2088 posts
Location
South Africa
Posted 30 March 2013 - 05:52 AM
Oh dang it. Didn't read the last part of the OP properly :P/>
Thought he would only use strings with single brackets.