Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Uglypoe 557 Donator Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
P100D 590 Moderation Voter
8 years ago

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

Ad

Answer this question