string - Use of '*' and '+' in Lua pattern -


i, j = string.find("the number 1298 even", "%d+") print(i,j) 

in above code, if use %d+, 12,15 expected %d* , returns 1,0. difference between 2 * accepts 0 value + accepts 1 or more. why returning 1,0?

first, pattern %d+ matches 1 or more digits, , %d* matches 0 or more digits, in example, %d+ matches "1298", while %d* matches empty string in beginning. 0 occurrence of digits can matched %d*, that's difference between + , *.

second, index 1 , 0 empty string seems bit odd, makes sense. index 1 means beginning of string, end index of empty string, can't have 1 because mean match first character "t", must less beginning index, 0 1 got.

furthermore, return value of string.find() can used arguments string.sub() substring found. in call string.sub (s, i, j), if i greater j, returns empty string.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -