# tmuxp.cli.search.compile_search_patterns

- **Module:** tmuxp.cli.search
- **Package:** tmuxp
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/tmuxp/blob/153acdf6ff1268b14d3d03ed488f545a7123c8f1/src/tmuxp/cli/search.py#L345
- **Page:** https://libtmux.org/en/py/stable/workspace/reference/tmuxp-cli-search-compile_search_patterns/

```
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:

```python
>>> 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:

```python
>>> 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):

```python
>>> 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):

```python
>>> 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):

```python
>>> 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:

```python
>>> 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`](https://docs.python.org/3/library/re.html#re.error): If a pattern is invalid regex (when fixed_strings=False).
