172 posts
Location
USA
Posted 10 November 2016 - 07:48 PM
Hi Guys!
I have a string and it contains print("Hi"). I am trying to remove everything in that statement except the actual thing it is trying to print.
I tried this
str:gsub('("', "")
but nothing worked sadly. When i do that, it returns (Hi)
Thanks!
1583 posts
Location
Germany
Posted 10 November 2016 - 08:58 PM
string.gsub uses patterns AFAIK and "(" and ")" are special characters. Try this:
str:gsub("%(","")
But you could also do something like this:
local what = str:match "print%((.+)%)"
This matches (or atleast should) everything inside the parantheses.
Edited on 10 November 2016 - 08:00 PM
463 posts
Location
Star Wars
Posted 11 November 2016 - 10:08 AM
Or try:
str:match 'print(%b())'
but note that calls can also be:
print ''
print ""
print [[]]
print {}
print ()
Edited on 12 November 2016 - 11:20 PM
1583 posts
Location
Germany
Posted 11 November 2016 - 01:50 PM
Or try:
str:match 'print%b()'
but note that calls can also be:
print ''
print ""
print [[]]
print {}
print ()
Your pattern doesn't work. Partially for the same reason OP's pattern won't work.
463 posts
Location
Star Wars
Posted 13 November 2016 - 12:21 AM
I forgot some brackets, thanks ^^.
I edited it in my preview post.
Edited on 12 November 2016 - 11:22 PM