var = "(I do not enjoy pineapple pizza.)" var = string.gsub(var, "(", "") var = string.gsub(var, ")", "") print(var)
I want to know how to remove parentheses from a string. The code provided gives error "Invalid pattern capture."
Hey Shaddy, what you're finding here is lua recognizing that as a magic character.
() are part of the magic characters and have special meaning when used in a pattern, more information can be found here.
In order for you to just get the ( part of the string you want to use % which allows you to escape it from being recognized as a pattern, and just taken as a simple string.
Example:
local var = "(I do not enjoy pineapple pizza.)" var = string.gsub(var, "%(", "") var = string.gsub(var, "%)", "") print(var) --> I do not enjoy pineapple pizza.