Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

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

API reference · Markdown

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]
function [source]
function [source]
tmuxp.cli.search.compile_search_patterns

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"))
True

Case-insensitive matching:

>>> tokens = [SearchToken(fields=("name",), pattern="DEV")]
>>> patterns = compile_search_patterns(tokens, ignore_case=True)
>>> bool(patterns[0].regex.search("development"))
True

Smart-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"))
False

Smart-case (lowercase = case-insensitive):

>>> tokens = [SearchToken(fields=("name",), pattern="dev")]
>>> patterns = compile_search_patterns(tokens, smart_case=True)
>>> bool(patterns[0].regex.search("DEVELOPMENT"))
True

Fixed 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"))
False

Word 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).

Esc

Type to search.