```
SELECT version();

┌─version()────┐
│ 21.10.1.8002 │
└──────────────┘

WITH lower('\RealVNC\WinVNC4 /v password') as CommandLine
SELECT 
    CommandLine,
    CommandLine LIKE '%\\\\realvnc\\\\winvnc4%password%' as t1,
    CommandLine LIKE '%\\\\realvnc\\\\winvnc4 %password%' as t2,
    CommandLine LIKE '%\\\\realvnc\\\\winvnc4%password' as t3,
    CommandLine LIKE '%\\\\realvnc\\\\winvnc4 %password' as t4,
    CommandLine LIKE '%realvnc%winvnc4%password%' as t5,
    CommandLine LIKE '%\\\\winvnc4%password%' as t6;

┌─CommandLine──────────────────┬─t1─┬─t2─┬─t3─┬─t4─┬─t5─┬─t6─┐
│ \realvnc\winvnc4 /v password │  0 │  1 │  1 │  1 │  1 │  1 │
└──────────────────────────────┴────┴────┴────┴────┴────┴────┘

1 rows in set. Elapsed: 0.001 sec. 
```

All should match.

http://sqlfiddle.com/#!9/73f0c6/2
{
    res = "";
    if (pattern.size() < 2 || pattern.front() != '%' || pattern.back() != '%')
        return false;
    res.reserve(pattern.size() * 2);
    const char * pos = pattern.data();
    const char * end = pos + pattern.size();
    ++pos;
    --end;
    while (pos < end)
    {
        switch (*pos)
        {
            case '%':
            case '_':
                return false;
            case '\\':
                ++pos;
                if (pos == end)
                    return false;
                else
                    res += *pos;
                break;
            default:
                res += *pos;
                break;
        }
        ++pos;
    }
    return true;