# Ripgrep Regex Size Limit: How to Fix the 100 MiB Compilation Error

> Encounter the ripgrep regex size limit 100 MiB error? Learn how to fix this compilation issue by overriding the limit or switching to the PCRE2 engine.

- Repository: [Andrew Gallant/ripgrep](https://github.com/BurntSushi/ripgrep)
- Tags: internals
- Published: 2026-03-05

---

**Ripgrep enforces a default 100 MiB limit on compiled regex memory usage to prevent runaway memory consumption, which you can override using the `--regex-size-limit` flag or bypass entirely by switching to the PCRE2 engine.**

Ripgrep (rg) compiles all search patterns into a single in-memory regular expression object for efficient matching. By default, the **ripgrep regex size limit** is set to 100 MiB (104,857,600 bytes) to protect against excessive memory use, as implemented in the BurntSushi/ripgrep source code. When your patterns exceed this threshold—common with large Unicode character classes or extreme repetition counts—the search fails with a compilation error before any files are scanned.

## Where the 100 MiB Limit Is Defined

The default limit is hardcoded in the regex engine configuration struct. In [`crates/regex/src/config.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/regex/src/config.rs), the `size_limit` field is initialized as:

```rust
size_limit: 100 * (1 << 20),   // 100 MiB

```

This value represents the maximum number of bytes allowed for the compiled regex object that holds all patterns supplied to ripgrep. The limit applies to the total memory footprint of the compiled automaton, not the length of your pattern string.

## Recognizing the Size Limit Error

When compilation exceeds the configured threshold, the regex engine returns an `Error::regex` variant defined in [`crates/regex/src/error.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/regex/src/error.rs). The user-facing message follows this format:

```

compiled regex exceeds size limit of {size_limit}

```

You will encounter this error when using patterns with massive repetition counts (e.g., `\pL{1000}`) or when supplying thousands of patterns simultaneously.

## How to Work Around the Ripgrep Regex Size Limit

### Increase the Limit with `--regex-size-limit`

The most direct solution is raising the limit via the command-line flag defined in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs). The `RegexSizeLimit` struct exposes this option with support for human-readable suffixes:

```bash
rg '\pL{1000}' --regex-size-limit 1G

```

Valid suffixes include:
- **K** for kilobytes
- **M** for megabytes  
- **G** for gigabytes

If you omit the suffix, the value is interpreted as raw bytes.

### Split Patterns into Separate Compilations

Rather than compiling one massive regex, decompose your search into smaller sub-patterns. Each pattern supplied via separate `-e` or `--regexp` arguments, or via a pattern file using `-f patterns.txt`, is compiled individually:

```bash

# Using multiple -e flags

rg -e '\pL{500}' -e '\pL{400}' -e '\pL{100}'

# Using a pattern file

rg -f patterns.txt

```

This approach keeps each compiled object well under the 100 MiB threshold without requiring a global limit increase.

### Use the PCRE2 Engine Instead

The PCRE2 backend (`--pcre2`) does not enforce the ripgrep regex size limit. Switching engines bypasses the restriction entirely, though you lose certain optimizations specific to the default Rust regex engine:

```bash
rg '\pL{1000}' --pcre2

```

Note that when `--pcre2` is active, the `--regex-size-limit` flag is ignored, as documented in the FAQ sections of the codebase.

### Reduce Pattern Complexity

Before increasing limits, simplify patterns containing expansive character classes or excessive repetition. Replace `\pL{1000}` with more specific constraints or limit quantifiers to reasonable ranges. This reduces the automaton size without changing search semantics.

## Practical Examples

The following commands demonstrate common scenarios and solutions:

```bash

# Fails with default 100 MiB limit

$ rg '\pL{1000}'
Compiled regex exceeds size limit of 104857600 bytes.

# Succeeds by raising limit to 1 GiB

$ rg '\pL{1000}' --regex-size-limit 1G
[search results...]

# Succeeds by splitting into smaller patterns

$ cat > patterns.txt << EOF
\pL{500}
\pL{400}
\pL{100}
EOF
$ rg -f patterns.txt
[search results...]

# Succeeds using PCRE2 (no size limit enforced)

$ rg '\pL{1000}' --pcre2
[search results...]

```

## Summary

- The **ripgrep regex size limit** defaults to **100 MiB** (104,857,600 bytes) to prevent excessive memory consumption, defined in [`crates/regex/src/config.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/regex/src/config.rs).
- Exceeding the limit produces the error "compiled regex exceeds size limit" generated in [`crates/regex/src/error.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/regex/src/error.rs).
- You can **increase the limit** using `--regex-size-limit` with K/M/G suffixes (parsed in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs)).
- **Splitting patterns** across multiple `-e` flags or a pattern file (`-f`) compiles each pattern separately, avoiding the single-object limit.
- The **PCRE2 engine** (`--pcre2`) bypasses the size limit entirely, though it uses a different regex backend.
- Raising the limit requires sufficient physical RAM; the compiled regex occupies proportionate memory during execution.

## Frequently Asked Questions

### What is the default ripgrep regex size limit?

The default limit is **100 MiB** (104,857,600 bytes). This value is defined in [`crates/regex/src/config.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/regex/src/config.rs) as `size_limit: 100 * (1 << 20)` and protects against patterns that would consume excessive memory during compilation.

### How do I increase the regex size limit in ripgrep?

Use the `--regex-size-limit` flag followed by a size value. You can specify bytes directly or use suffixes: `K` for kilobytes, `M` for megabytes, or `G` for gigabytes. For example, `--regex-size-limit 500M` raises the cap to 500 megabytes.

### Does the PCRE2 engine have a size limit?

No. When you invoke ripgrep with `--pcre2`, the 100 MiB regex size limit does not apply. The PCRE2 engine manages its own memory constraints independently, making it suitable for extremely large patterns that exceed the default engine's limit.

### Why does ripgrep enforce a regex size limit?

The limit prevents **runaway memory use** when compiling pathological patterns. Without it, a pattern like `\pL{1000000}` could attempt to allocate gigabytes of RAM for the automaton. The 100 MiB default, as documented in [`crates/core/flags/defs.rs`](https://github.com/BurntSushi/ripgrep/blob/main/crates/core/flags/defs.rs), is generous enough for reasonable patterns while protecting system resources.