3

Is it possible to take this:

a=[[do end workspace.Part["Child 1"].Object.child2["thing"]remove() do end]]
a=a:gsub("%.%a+","{F}%0{F}")  
a=a:gsub('(%[%s*([\'"]?).*%2%s*%]):remove%(%)','{F}%1{F}:remove()')
a=a:gsub('{F}%s*{F}','')
a=a:gsub('{F}.-{F}','filterremove(%0)')

Output: do end filterremove(Workspace.Part["Child 1"].Object.child2["thing"]) do end

and use only one gsub to have the same result, rather than two? regardless of the combination of x.y, x[y], [x][y], etc.

9
  • 2
    Provide the sample input and output strings? Commented Feb 28, 2013 at 13:42
  • Input: workspace.Part["Child"]:remove(), Output: filterremove(workspace.Part["Child"]) Commented Feb 28, 2013 at 15:20
  • a=a:gsub("(.*)%:remove%(%)", "filterremove(%1)") <- works fine. Commented Feb 28, 2013 at 15:25
  • That will try to put the entire program up to 'remove' into one function. Commented Feb 28, 2013 at 15:26
  • 1
    Relevant. You can't get there from here. Commented Feb 28, 2013 at 16:31

2 Answers 2

1

a:gsub("(%S*%b[]):remove%(%)", "filterremove(%1)")

Sign up to request clarification or add additional context in comments.

1 Comment

I know, but then you need to specify an example you want to see working. Or several examples. As soon as someone comes up with implementation that satisfies them, you get what you need.
1

You can at least chain and line-wrap it:

a = [[do end workspace.Part["Child 1"]:remove() do end]]
a = a:gsub("%.%a+","{F}%0{F}")  
     :gsub('(%[%s*([\'"]?).*%2%s*%]):remove%(%)','{F}%1{F}:remove()')
     :gsub('{F}%s*{F}','')
     :gsub('{F}.-{F}','filterremove(%0)')

Really though, this is never going to work. What about:

workspace.remove(x)
workspace["remove"](x)
getfenv()["work" .. "space"]["re".."move"](x)

4 Comments

and what about spaces: workspace . Part["..."] :remove(); OP needs to make at least some assumptions...
@Paul: I don't think the OP can afford to make any assumptions, since they are almost certainly trying to sandbox unknown code.
I wasn't aware of that, but if that's the case these attempts are futile.
Spaces are not a problem. %s*, now forget about it. Concatenation and variables where I can't catch whether or not it is using 'remove' is the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.