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

When using String.Match, how can you specify certain characters?

For example, I have this line of code:

print(string.match("test!/Uglypoe","%w+"))

This would print only "test". How could I change it so that it would get all alphanumeric characters (%w+) as well as certain characters (such as !, ?, and /).

1 answer

✓ Accepted answer

This isn't really a LUA question and more of a regex question. I would encourage you to read up on regular expressions. However, I will help you with your question. I really don't understand what you're trying to match in your string, but if you want to match alphanumeric, you would use [a-zA-Z0-9]. If you want to match the characters !?/, you would use [\!\?\/].

Example usage: You want to find an alphanumeric string between two characters that are either ! or ? or /, in the format !teststring1!

The regex to match this would be ([\!\?\/])[a-zA-Z0-9]+\1

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