```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| │
└─────────────────┘
```
}
                else
                    now += s[i + 1]; 
                ++i;
            }
            else
                now += s[i]; 
        }
        if (!now.empty())
        {
            instructions.emplace_back(-1, now);
            now = "";
        }
        for (const auto & it : instructions)
            if (it.first >= num_captures)
                throw Exception(
                    "Invalid replace instruction in replacement string. Id: " + toString(it.first) + ", but regexp has only "
                        + toString(num_captures - 1) + " subpatterns",
                    ErrorCodes::BAD_ARGUMENTS);
        return instructions;
    }
    static void processString(
        const re2_st::StringPiece & input,
        ColumnString::Chars & res_data,
        ColumnString::Offset & res_offset,
        re2_st::RE2 & searcher,
        int num_captures,
        const Instructions & instructions)
    {
        re2_st::StringPiece matches[max_captures];