like¶
Whether text matches a pattern
x like y like[x;y]
Where
xis a symbol or stringyis a pattern as a string
returns a boolean: whether x matches the pattern of y. Matching is case-sensitive.
q)`quick like "qu?ck"
1b
q)`brown like "br[ao]wn"
1b
q)`quickly like "quick*"
1b
q)`quick like "Qu*"
0b
q)"a*b" like "a[*]b" / match a pattern character literally
1b
If y contains no pattern characters, like is equivalent to {y~string x}.
q)`quick like "quick"
1b
q)`quick like "quickish"
0b
Implicit iteration¶
like applies to lists of strings or symbols, and to dictionaries with them as values.
q)`brawn`brown like "br[^o]wn"
10b
q)(`a`b`c!`quick`brown`fox)like "brown"
a| 0
b| 1
c| 0
Perl-compatible regular expressions¶
like supports only a limited set of pattern characters. For full regular expressions, including alternation, optional items, repetition counts, and case-insensitive matching, use the PCRE2 module.
q)`colour`Color like "colo*r"
10b
q)pcre2:use`kx.fusion:pcre2
q)pcre2.match["colou?r";"Colour or color";`caseless]
x0| "Colour" 0 6 "color" 10 15