Check if a certain text is in quotes

Hello, just for some clarification. I am creating a plugin that goes through the script and does specific stuff. I recently checked the forum, and found out you can find comments within a script using string:gsub. I was wondering if you could do this for text in a string.

For example:

  • Plugin outputs scripts code using instance.Source
  • print("Hello World")
  • Plugin sees 'Hello World is in quotes, and outputs ‘Hello World’

I believe gsub is for substitution.
Have you tried string.match(’“HelloWorld”’,’"’) that is surround the double quotes with single quotes.

One string pattern is %bxy

“The balanced capture matching x, y, and everything between (for example, %b() matches a pair of parentheses and everything between them)”

So a pattern like this should work:

local capture = string.match(TEXTHERE, '%b""')
1 Like

Thanks for the responses, they both helped me conclude a working piece, thanks to all who helped!