daft.Expression.str.count_matches#
- Expression.str.count_matches(patterns: Any, whole_words: bool = False, case_sensitive: bool = True)[source]#
Counts the number of times a pattern, or multiple patterns, appear in a string.
Note
If a pattern is a substring of another pattern, the longest pattern is matched first. For example, in the string “hello world”, with patterns “hello”, “world”, and “hello world”, one match is counted for “hello world”.
If whole_words is true, then matches are only counted if they are whole words. This also applies to multi-word strings. For example, on the string “abc def”, the strings “def” and “abc def” would be matched, but “bc de”, “abc d”, and “abc “ (with the space) would not.
If case_sensitive is false, then case will be ignored. This only applies to ASCII characters; unicode uppercase/lowercase will still be considered distinct.
- Parameters:
patterns – A pattern or a list of patterns.
whole_words – Whether to only match whole word(s). Defaults to false.
case_sensitive – Whether the matching should be case sensitive. Defaults to true.