String Pattern: Matching Lowercase and Uppercase of a Specific Letter

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

For the pattern for uppercase and lowercase, it should accept See, sEe, and sEE.

For the pattern for one or more number of specific letters, it should accept sEEE, sEEEE, sEEEEE

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.upper or 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.

“[sS][eE]+”

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 [cdl]og:
cog, dog, log are all matches, as well as dog in doggy and log in Tagalog, but
bog, frog, dork, and 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 [^cdl]og:
bog, aog, oog, -og, /og, 5og, are all matches, as well as rog in frog, but
dog, log, and cog are not matches, neither is log in Tagalog.

You can also match ranges of letters.
The set [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.