```sql
SELECT replaceRegexpAll('a', 'z*', '')
```

```
┌─replaceRegexpAll('a', 'z*', '')─┐
│                                 │
└─────────────────────────────────┘
```

```sql
SELECT replaceRegexpAll('aaaa', 'z*', '')
```

```
┌─replaceRegexpAll('aaaa', 'z*', '')─┐
│ aaa                                │
└────────────────────────────────────┘
```

Please create another issue.

_Originally posted by @alexey-milovidov in https://github.com/ClickHouse/ClickHouse/issues/35046#issuecomment-1061220789_
int num_captures,
        const Instructions & instructions)
    {
        re2_st::StringPiece matches[max_captures];
        size_t copy_pos = 0;
        size_t match_pos = 0;
        while (match_pos < static_cast<size_t>(input.length()))
        {
            
            bool can_finish_current_string = false;
            if (searcher.Match(input, match_pos, input.length(), re2_st::RE2::Anchor::UNANCHORED, matches, num_captures))
            {
                const auto & match = matches[0];
                size_t bytes_to_copy = (match.data() - input.data()) - copy_pos;
                
                res_data.resize(res_data.size() + bytes_to_copy);
                memcpySmallAllowReadWriteOverflow15(&res_data[res_offset], input.data() + copy_pos, bytes_to_copy);
                res_offset += bytes_to_copy;
                copy_pos += bytes_to_copy + match.length();
                match_pos = copy_pos;
                
                for (const auto & it : instructions)
                {
                    if (it.substitution_num >= 0)
                    {
                        const auto & substitution = matches[it.substitution_num];
                        res_data.resize(res_data.size() + substitution.length());
                        memcpy(&res_data[res_offset], substitution.data(), substitution.length());
                        res_offset += substitution.length();
                    }