문제

a, i, c = string.find(s, '"("?)', i + 1)

What is role of ? here? I believe it was checking for double quotes but I really do not understand exactly the use of "("?).

I read that string.find returns the starting and ending index of the matched pattern. But as per above line of code, a, i and c, 3 values are being returned. What is the third value being returned here?

도움이 되었습니까?

해결책

? matches an optional character, i.e, zero or one occurrence of a character. So the pattern "("?) matches a ", followed by an optional ", i.e, it matches either " or "". Note that the match for "?(zero or one ") is captured.

As for the return value of string.find(), from string.find():

If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.

The capture is the third return value, when there is a successful match.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top