tmuxp.cli.search.compile_search_patterns
Python
- Python
- Ruby Unavailable
- Lua Unavailable
- TypeScript Unavailable
- Rust Unavailable
- Go Unavailable
- Java Unavailable
- .NET Unavailable
- C++ Unavailable
- Swift Unavailable
- tmuxp.cli.search.compile_search_patterns ( tokens : list[SearchToken] , ignore_case : bool = False , smart_case : bool = False , fixed_strings : bool = False , word_regexp : bool = False ) list[SearchPattern]
-
Compile search tokens into regex patterns.
Examples
Basic compilation:
>>> tokens = [SearchToken(fields=("name",), pattern="dev")]>>> patterns = compile_search_patterns(tokens)>>> patterns[0].raw'dev'>>> bool(patterns[0].regex.search("development"))TrueCase-insensitive matching:
>>> tokens = [SearchToken(fields=("name",), pattern="DEV")]>>> patterns = compile_search_patterns(tokens, ignore_case=True)>>> bool(patterns[0].regex.search("development"))TrueSmart-case (uppercase = case-sensitive):
>>> tokens = [SearchToken(fields=("name",), pattern="Dev")]>>> patterns = compile_search_patterns(tokens, smart_case=True)>>> bool(patterns[0].regex.search("Developer"))True>>> bool(patterns[0].regex.search("developer"))FalseSmart-case (lowercase = case-insensitive):
>>> tokens = [SearchToken(fields=("name",), pattern="dev")]>>> patterns = compile_search_patterns(tokens, smart_case=True)>>> bool(patterns[0].regex.search("DEVELOPMENT"))TrueFixed strings (escape regex metacharacters):
>>> tokens = [SearchToken(fields=("name",), pattern="dev.*")]>>> patterns = compile_search_patterns(tokens, fixed_strings=True)>>> bool(patterns[0].regex.search("dev.*project"))True>>> bool(patterns[0].regex.search("development"))FalseWord boundaries:
>>> tokens = [SearchToken(fields=("name",), pattern="dev")]>>> patterns = compile_search_patterns(tokens, word_regexp=True)>>> bool(patterns[0].regex.search("my dev project"))True>>> bool(patterns[0].regex.search("development"))False- Parameters
-
-
tokens ( list[SearchToken] ) – Parsed search tokens to compile.
-
ignore_case ( bool ) – If True, always ignore case. Default False.
-
smart_case ( bool ) – If True, ignore case unless pattern has uppercase. Default False.
-
fixed_strings ( bool ) – If True, treat patterns as literal strings, not regex. Default False.
-
word_regexp ( bool ) – If True, match whole words only. Default False.
-
- Returns
-
list[SearchPattern] List of compiled search patterns.
- Raises
-
-
re.error – If a pattern is invalid regex (when fixed_strings=False).
-