You can use string.find which returns where this string was found.
print(string.find("11221232122", "3")) -- 7 7
string.find returns both where the match starts and where the match ends, since it’s just 1 character in this case it starts and ends at the same place.
string.find() returns where does the first match found starts and ends. Like in incapaz’s example, the pattern “3” is found at 7th character and ends at 7th character. If we change “3” to “321” it will return 7 9 because the specified pattern is first found at 7th character and continues to the 9th character in the string.
You might be wondering why this function returns another value that specifies where does the string pattern end since naturally you would know how long would be your string pattern be but this function also support character classes like %w (%w is used for matching alphanumeric characters.) unless specified otherwise by passing the 4th argument when firing the function to true.
Here is an example:
print(string.find("!+-hello/*//", "%w+")) --%w is used for only matching an alphanumeric character (Letters and numbers.). The "+" sign next to it is used to match at least 1 or more of the specified character class. Without the "+" sign it would output as "4 4".
--Output
-> 4 8