github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/stdlib/string/testdata/find.lua (about)

     1  x, y = string.find("abcabc", "bca")
     2  
     3  assert(x == 2 and y == 4)
     4  
     5  x, y = string.find("abcabc", "b", 3)
     6  
     7  assert(x == 5 and y == 5)
     8  
     9  x, y = string.find("abcabc", "$")
    10  
    11  assert(x == 7 and y == 6)
    12  
    13  x, y = string.find("abcabc", "^")
    14  
    15  assert(x == 1 and y == 0)
    16  
    17  x, y = string.find("abcabc", ".c")
    18  
    19  assert(x == 2 and y == 3)
    20  
    21  x, y = string.find(" abc abc", "%w+")
    22  
    23  assert(x == 2 and y == 4)
    24  
    25  x, y = string.find("abc", "^[a-z]+$")
    26  
    27  assert(x == 1 and y == 3)
    28  
    29  assert(string.find("()", "^[a-z]+$") == nil)
    30  
    31  x, y = string.find("", "")
    32  
    33  assert(x == 1 and y == 0)
    34  
    35  x, y = string.find(" \r\n ab abc", "%g%g%g")
    36  
    37  assert(x == 8 and y == 10)
    38  
    39  x, y, z = string.find("xy", "x()y")
    40  
    41  assert(x == 1 and y == 2 and z == 2)