Shouldn’t ("bar"):find("(foo)?bar") return 1, 3?
print(("bar"):find("(foo)*bar")) and print(("bar"):find("(foo)-bar")) won’t work either.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is because parentheses in Lua’s patterns (quite unfortunately) do not serve as a grouping construct, only as a delimiters of capturing groups. When you write a pattern
(foo)?bar, Lua interprets it as “matchf,o,o,?,b,a,r, capturefooin a group”. Here is a link to a demo. Unfortunately, the closest you can get to the behavior that you wanted isf?o?o?bar, which of course would also matchfbarandoobar, among other wrong captures.this code
returns 1 3