Up | TOC | Index | |||||
<< 7 Included Tools | < 8.21 Text Manipulation | Up: 8 API Reference | 8.23 Base 64 Encoding/Decoding > | 9 Release Notes >> |
8.22 Wildcard Matching
8.22.1 Routines
8.22.1.1 is_match
include std/wildcard.e namespace wildcard public function is_match(sequence pattern, sequence string)
Determine whether a string matches a pattern. The pattern may contain * and ? wildcards.
Parameters:
- pattern : a string, the pattern to match
- string : the string to be matched against
Returns:
An integer, TRUE if string matches pattern, else FALSE.
Comments:
Character comparisons are case sensitive. If you want case insensitive comparisons, pass both pattern and string through upper(), or both through lower(), before calling is_match().
If you want to detect a pattern anywhere within a string, add * to each end of the pattern:
i = is_match('*' & pattern & '*', string)
There is currently no way to treat * or ? literally in a pattern.
Example 1:
i = is_match("A?B*", "AQBXXYY") -- i is 1 (TRUE)
Example 2:
i = is_match("*xyz*", "AAAbbbxyz") -- i is 1 (TRUE)
Example 3:
i = is_match("A*B*C", "a111b222c") -- i is 0 (FALSE) because upper/lower case doesn't match
Example 4:
bin/search.ex
See Also:
upper, lower, Regular Expressions