-- _search_.e
-- _search_.e
Following global functions are defined:
reverse find an object in a sequence
Params:object to search for
sequence to search in
optional "upto" value indicates index to search to: defaults to 1
searches object from the end of the sequence to the beginning
index of object's position in the sequence
printf(1, "%d\n", rfind('a', "123a 56", {}))
4
printf(1, "%d\n", rfind('a', "123a 56", {{"upto", 5}}))
0
printf(1, "%d\n", rfind('a', {"123", 'a', "456a", "a"}, {}))
2
printf(1, "%d\n", rfind('a', {"123", 'a', "456a", "a"}, {{"upto", 3}}))
0
find(), match()
find all positions of an item in a sequence
Params:item to search for
sequence to search in
optional "from" value indicates index to search from: defaults to 1
sequence
list of indexes of all object's positions in the sequence
print(1, find_all('a', "abracadabra", {}))
puts(1, "\n")
{1,4,6,8,11}
print(1, find_all('a', "abracadabra", {{"from", 5}}))
puts(1, "\n")
{6,8,11}
print(1, find_all("a", {"what", "a", "pity", "a", "shame"}, {}))
puts(1, "\n")
{2,4}
print(1, find_all("a", {"what", "a", "pity", "a", "shame"}, {{"from", 3}}))
puts(1, "\n")
{4}
match all positions of an item in a sequence
Params:item to search for
sequence to search in
optional "from" value indicates index to search from: defaults to 1
sequence
list of indexes of all object's positions in the sequence
print(1, match_all("a", "abracadabra", {}))
puts(1, "\n")
{1,4,6,8,11}
print(1, match_all("a", "abracadabra", {{"from", 5}}))
puts(1, "\n")
{6,8,11}
find first position of any item from a list in a sequence
Params:list of items to search for
sequence to search in
optional "from" value indicates index to search from: defaults to 1
integer
position of the first item found
printf(1, "%d\n", find_any({"c", "e", "d"}, {"ab", "c", "d"}, {}))
2
printf(1, "%d\n", find_any({"c", "e", "d"}, {"ab", "c", "d"}, {{"from", 3}}))
3
match first position of any item from a list in a sequence
Params:list of items to search for
sequence to search in
optional "from" value indicates index to search from: defaults to 1
{integer, sequence}
position of the first item that matches and matched item
printf(1, "%d\n", match_any({"c", "e", "d"}, "abracadabra", {}))
{5, "c"}
printf(1, "%d\n", match_any({"c", "e", "d"}, "abracadabra", {{"from", 6}}))
{7, "d"}
returns length of common portion of 2 sequences
Params: