I know that you can't repeat match groups in Lua. For example, if I wanted to match the two successive "45"'s, I can't do:
print(string.find("some 4545 text", "(%d%d)+"))
which will print nil (no match found).
However, since find(...) doesn't report an error (for the invalid patterns "%" and "(%d" errors are produced), it leads me to believe the pattern "(%d%d)+" is a valid one.
If "(%d%d)+" is a valid pattern, what does it match? And if it isn't, is there a particular reason no error is produced?
"(%d%d)+" is a valid pattern. It matches for example "some 45+67 text" or "some 4567+ text" and captures "45" in the first case and "67" in the second.
To match two successive occurrences of a string of digits, use "(%d+)%1".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With