Search code examples
lua

Difference between %S and %s in lua


According to the book, this part of code is dividing a line in 2 parts, I do not understand the difference between %S and %s ,neither how exactly is it dividing it in two parts.

local namefrom, nameto = string.match(line, "(%S+)%s+(%S+)")

Solution

  • According to the documentation, %s means whitespace, and %S means anything other than whitespace. So that match expression will split on one or more whitespace characters, capturing the two strings on either side.