Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

string.gsub parentheses error "Invalid pattern capture?" (Code provided)

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."

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.