I want to know how do i obtain the text inside brackets
ex: [lol] will return lol and [[fdfsdfsdf]] will return [fdfsdfsdf]
get text in brackets
Started by FuuuAInfiniteLoop(F.A.I.L), Mar 29 2013 02:40 PM
4 replies to this topic
#1
Posted 29 March 2013 - 02:40 PM
#2
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]
#3
Posted 30 March 2013 - 01:04 AM
pattern of
'%[(.-)%]'works too. Curious to know if there's a difference though.
#4
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".
#5
Posted 30 March 2013 - 05:52 AM
Oh dang it. Didn't read the last part of the OP properly 
Thought he would only use strings with single brackets.
Thought he would only use strings with single brackets.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











