# libtmux.formats._open_expression

- **Module:** libtmux.formats
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/d2a146c9a045437b92013d65943b7ac70013fa24/src/libtmux/formats.py#L86
- **Page:** https://libtmux.org/en/py/latest/reference/libtmux-formats-_open_expression/

```
libtmux.formats._open_expression(
    template: str,
) -> str | None
```

Return which tmux expression *template* ends inside, if any.

Mirrors the scanner in tmux's ``format_expand1``: ``#(...)`` closes at
its balancing ``)``, counting every ``(`` inside it; ``#{...}`` closes
as :func:`_skip` finds; a run of ``#`` before ``[`` is a style.

## Parameters

- `template` (`str`)

## Examples

```python
>>> _open_expression("#{session_name}-") is None
True
>>> _open_expression("#{?pane_active,")
'it ends inside #{...}'
>>> _open_expression("#(echo $(printf x)")
'it ends inside #(...)'
>>> _open_expression("#(echo $(printf x))") is None
True
>>> _open_expression("#[fg=")
'it ends inside #[...]'
```
