```sql
SELECT trim(BOTH ', ' FROM '5935,5998,6014, ')||'|' x

SELECT concat(replaceRegexpAll('5935,5998,6014, ', concat('^[', regexpQuoteMeta(', '), ']*|[', regexpQuoteMeta(', '), ']*$'), ''), '|') AS x

┌─x─────────────────┐
│ 5935,5998,6014, | │
└───────────────────┘

psql> SELECT trim(BOTH ', ' FROM '5935,5998,6014, ')||'|'
5935,5998,6014|

```
http://sqlfiddle.com/#!17/0a28f/406

though trailing
```sql
SELECT trim(trailing ', ' FROM '5935,5998,6014, ')||'|' x
┌─x───────────────┐
│ 5935,5998,6014| │
└─────────────────┘
```
const ColumnString::Chars & data,
        const ColumnString::Offsets & offsets,
        const std::string & needle,
        const std::string & replacement,
        ColumnString::Chars & res_data,
        ColumnString::Offsets & res_offsets)
    {
        ColumnString::Offset res_offset = 0;
        res_data.reserve(data.size());
        size_t size = offsets.size();
        res_offsets.resize(size);
        typename re2_st::RE2::Options regexp_options;
        
        regexp_options.set_log_errors(false);
        re2_st::RE2 searcher(needle, regexp_options);
        int num_captures = std::min(searcher.NumberOfCapturingGroups() + 1, static_cast<int>(max_captures));
        Instructions instructions = createInstructions(replacement, num_captures);
        
        for (size_t i = 0; i < size; ++i)
        {
            int from = i > 0 ? offsets[i - 1] : 0;
            re2_st::StringPiece input(reinterpret_cast<const char *>(data.data() + from), offsets[i] - from - 1);
            processString(input, res_data, res_offset, searcher, num_captures, instructions);
            res_offsets[i] = res_offset;
        }
    }
    static void vectorFixed(