# Colorize Text with Regex Rules

Highlight log or command output with user-defined regex color rules, then export ANSI terminal escapes or self-contained HTML.

## Run it

- **CLI:** `gizza tool text-colorizer "INFO service started
WARN retrying request
ERROR database timeout" 'rules=bold red: \bERROR\b
yellow: \bWARN(ING)?\b
green: \bOK\b'`
- **Web:** https://gizza.ai/tools/text-colorizer/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/text-colorizer/tool.json

## Inputs

- `text` — Text _(field)_
- `rules` — Rules (color: regex) _(field)_
- `output` — Output format _(field)_
- `theme` — HTML theme _(field)_
- `ignore_case` — Ignore case _(field)_
- `whole_line` — Color whole matching lines _(field)_

## Output

- Colorized output (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `text` — Text
- `rules` — Rules (color: regex)
- `output` — Output format
- `theme` — HTML theme
- `ignore_case` — Ignore case
- `whole_line` — Color whole matching lines

Example: `https://gizza.ai/tools/text-colorizer/?text=INFO%20service%20started%0AWARN%20retrying%20request%0AERROR%20database%20timeout&rules=bold%20red%3A%20%5CbERROR%5Cb%0Ayellow%3A%20%5CbWARN%28ING%29%3F%5Cb%0Agreen%3A%20%5CbOK%5Cb&output=ansi&theme=dark&ignore_case=true&whole_line=true`

---

## Highlight logs and command output with repeatable rules

Text Colorizer applies a stack of `color: regex` rules to every line of pasted text. It is useful for
turning plain CI logs, command output, server logs, or grep results into terminal-colored ANSI text or
self-contained HTML you can paste into a report.

Rules are evaluated from top to bottom. Each rule uses the text before the first colon as the style and
the text after it as a Rust regular expression. Earlier rules win where matches overlap, so put the most
important patterns first.

## Worked example

Paste this text:

```text
INFO service started
WARN retrying request
ERROR database timeout
```

Then use these rules:

```text
bold red: \bERROR\b
yellow: \bWARN(ING)?\b
green: \bINFO\b
```

Choose **ANSI terminal escapes** to paste into a compatible terminal or **HTML `<pre>`** to produce a
small themed block for a web page or incident note.

## Rule syntax

- `red: ERROR` colors matching substrings red.
- `bold red: \bERROR\b` adds attributes before the foreground color.
- `green on black: \bOK\b` sets a background with `on <color>`.
- `#3465a4 underline: https?://\S+` uses a custom hex color.
- Turn on **Color whole matching lines** when you want a matching `ERROR` or `FAIL` to color the entire line.

## Limits and edge cases

- Input text is capped at 512 KiB and rules are capped at 200 lines.
- Rules use Rust regular expressions, not JavaScript-specific regex features.
- HTML output escapes unmatched text before wrapping styled matches, so pasted `<` and `&` are safe text.
- ANSI output includes escape characters; use HTML output when a destination does not interpret ANSI.

## FAQ

<details>
<summary>What colors and attributes can I use?</summary>

Named colors include black, red, green, yellow, blue, magenta, cyan, white, gray/grey, and bright variants
such as brightred and brightyellow. You can also use `#rgb` or `#rrggbb` hex colors. Attributes include
bold, dim, italic, underline, blink, reverse, and strike.

</details>

<details>
<summary>What happens when two rules match the same text?</summary>

The first rule in the list wins for the overlapping characters. Put high-priority rules such as `ERROR`
before broad catch-all patterns like `timeout|failed|error`.

</details>

<details>
<summary>Can I color an entire log line instead of just the matching word?</summary>

Yes. Enable **Color whole matching lines**. The first rule that matches anywhere on a line styles the
whole line, which is useful for CI statuses or severity-based log highlighting.

</details>

<details>
<summary>When should I choose ANSI versus HTML?</summary>

Choose ANSI when the result will be viewed in a terminal or a tool that understands escape codes. Choose
HTML when you want a portable preview block for documentation, incident notes, or web pages.

</details>

## Related tools

- [HTML Diff](https://gizza.ai/tools/html-diff/): Compare two HTML snippets by their visible text, ignoring tag and attribute noise.
- [Text Diff](https://gizza.ai/tools/text-diff/): Compare two text blocks and highlight added, removed, and changed lines.
- [Chat Transcript Formatter](https://gizza.ai/tools/chat-transcript-formatter/): Clean a messy chat log into one consistently-formatted transcript with normalized speakers, timestamps, and WhatsApp/IRC/plain line parsing.
- [Context Trimmer](https://gizza.ai/tools/context-trimmer/): Trim text to an approximate token budget for LLM prompts, keeping the head, tail, middle, or both ends. Runs locally in your browser.
- [Compare Two Lists](https://gizza.ai/tools/list-set-diff/): Compare two lists as sets and see which items are only in A, only in B, or shared — with counts. Ignore case, trim, dedupe, and leading zeros. Runs in your browser.
