in, !in, in~, !in~), see Set membership operators.
RHS = right-hand side of the expression
LHS = left-hand side of the expression
Case-sensitivity
Operators with_cs suffix are case-sensitive.
When two operators do the same task, use the case-sensitive one for better performance.
For example:
- Instead of
=~, use== - Instead of
has_any, usehas_any_cs - Instead of
contains, usecontains_cs
Best practices
- Use case-sensitive operators when you know the case to improve performance.
- Avoid complex regular expressions for basic matching tasks. Use basic string operators instead.
- When matching against a set of values, ensure the set is as small as possible to improve performance.
- For matching substrings, use prefix or suffix matching instead of general substring matching for better performance.
Equality and inequality operators
Operators:==!==~!~in!inin~!in~
- Use
==or!=for exact match comparisons when case sensitivity is important. - Use
=~or!~for case-insensitive comparisons or when you don’t know the exact case.
Subsequence-matching operators
Operators:contains!containscontains_cs!contains_csstartswith!startswithstartswith_cs!startswith_csendswith!endswithendswith_cs!endswith_cs
contains_cs, startswith_cs, endswith_cs) when you know the case to improve performance.
Regular-expression-matching operators
Operators:matches regex!matches regex
Term-matching operators
A term is a contiguous sequence of Unicode letters and numbers. Any other character, including spaces, hyphens, underscores, and dots, acts as a term boundary. For example,foo-bar and foo_bar each produce the terms foo and bar, so has "foo" matches both.
Operators:
has!hashas_cs!has_cshas_anyhas_any_cshasprefix!hasprefixhasprefix_cs!hasprefix_cshassuffix!hassuffixhassuffix_cs!hassuffix_cs
- Use
hasorhas_csfor term matching which can be more efficient than regular expression matching for simple term searches. - Use
has_anyorhas_any_csfor matching against multiple possible terms. - Use
has_csorhas_any_cswhen you know the case to improve performance. - Unlike the
containsoperator, which matches any substring, thehasoperator looks for exact terms, ensuring more precise results.