What is the match_any() method in Euphoria?
Overview
The match_any() method in Euphoria implements a search algorithm, which traverses the values of a list in search of a match with the values of another list. Simply put, this function checks if any value from a set of values can be found in another set of values.
When the match_any() method finds a match, it returns 1. Otherwise, when no match is found, it returns 0.
For instance, suppose we have two variables A = “in” and B = “minimal”. If we say match_any of A in B, that is match_any(A,B), the return value will be 1. This is because both “i” and “n” from A match some characters in “minimal” of variable B.
Syntax
Let’s look at the syntax of this method:
match_any(search_value, to_search, start_from)
Parameter values
search_value: This is the value whose match is being searched for in another set of values.to_search: This is the variable whose values are to be searched for a match with any of thesearch_value.start_from: This is the position at which we want the search for a match to begin. This is an optional parameter and has a default value of the first index.
Return value
This method returns the value 1 if a match is found and the value 0 if no match is found.
Example
Let’s look at an example of the match_any() method.
include std/search.esequence myseq1, myseq2, myseq3myseq1 = "This is educative"myseq2 = "iuc"myseq3 = "wyz"puts(1,"\"i\" or \"u\" or \"c\" can be found in \"This is educative\" so it returns :")print(1,match_any(myseq2, myseq1))puts(1,"\n none of \"wyz\" can be found in \"This is educative\" so it returns :")print(1, match_any(myseq3, myseq1))puts(1,"\n 2 comes before start_from parameter :")print(1, match_any({2}, {1,2,3,4,5}, 4))
Explanation
-
Line 1: We include the
search.emodule from the standard library. -
Line 3: We declare some variables.
-
Lines 5–7: We assign values to the variables we declared.
-
Line 10: We use the
match_anymethod to check if any of the characters in"uic"can be found in the value"This is educative". Then, we print the result. -
Line 13: We use the
match_anymethod to check if any of the characters in"wyz"can be found in the value"This is educative". Then, we print the result. -
Line 13: We use the
match_anymethod to check if2can be found in the set{1,2,3,4,5}, starting from the index position4. Then, we print the result.