Is there a string pattern for matching lowercase and uppercase of a specific letter?
Another thing is a pattern for one of more number of specific letters?
For example, let’s say I have a string
For the pattern for uppercase and lowercase, it should accept
For the pattern for one or more number of specific letters, it should accept
I did read the String Pattern Documentation, but I only found character classes.
I also thought of having a table containing the patterns, and just loop through it.
Another idea is attempting to use
string.lower, which solves my 1st question. But I don’t have a solution for the 2nd question.
If there is a shorter method of doing it, I would appreciate it.
In the first question, convert the string to lower if you don’t care about which case it was. If you do, use sets: “[sS][eE][eE]”.
To match one or more letters, use + after the symbol you want repeated.
Mind explaining how
[sS] matches one or more specific letters?
Actually, can you be explain how Sets work? I don’t really understand it.
There’s a lot going on with string patterns, and it would take me forever to explain it all. There are a lot of websites that teach Regular Expressions, and Lua’s string patterns are pretty similar.
Sets are groups of characters where anything inside can be matched.
[cdl] matches any of those letters contained within, so that in the pattern
log are all matches, as well as
apple are not matches.
[cCdDlL] matches upper or lowercase for any of those latters contained witin.
[^cdl] matches anything except the letters within, so that in the pattern the pattern
5og, are all matches, as well as
cog are not matches, neither is
You can also match ranges of letters.
[a-z] matches all lowercase letters. The set
[a-z0-9] matches all lowercase letters and numbers. The set
[a-fA-F0-9] matches uppercase or lowercase a through f and all numbers as you would see in hexadecimal.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.