```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| │
└─────────────────┘
```
extern const int BAD_ARGUMENTS;
}
/** Replace all matches of regexp 'needle' to string 'replacement'. 'needle' and 'replacement' are constants.
  * 'replacement' could contain substitutions, for example: '\2-\3-\1'
  */
template <bool replace_one = false>
struct ReplaceRegexpImpl
{
    
    
    
    
    using Instructions = std::vector<std::pair<int, std::string>>;
    static const size_t max_captures = 10;
    static Instructions createInstructions(const std::string & s, int num_captures)
    {
        Instructions instructions;
        String now;
        for (size_t i = 0; i < s.size(); ++i)
        {
            if (s[i] == '\\' && i + 1 < s.size())
            {
                if (isNumericASCII(s[i + 1])) 
                {
                    if (!now.empty())
                    {
                        instructions.emplace_back(-1, now);
                        now = "";
                    }
                    instructions.emplace_back(s[i + 1] - '0', String());