How to find rows matched by either whole string or with wildcard star character

The reason is we have, for instance, db table with text column like 'name' and we have to find rows that matches one from set and the set may contain strings with wildcard token '*' at the end. Yes, you know, we can change wildcard patterns to db standard wildcards: '%' or' _', but what if  we need to find also strings with those symbols too?

In unix/linux terminal you often write commands like 'find name_of_file*' to find all files matches pattern with wildcard. In frontend we want to let our backend support something similar without db/sql specific like constructions. It is secure do not let frontend/client app to control LIKE pattern straightly.

In this case we need to escape special sql wildcard characters for LIKE command with ESCAPE addition, so we need to write: LIKE 'string#_of#_text#_cr#%zy' ESCAPE '#'

Also, we have not just one string - we have set of strings. And we need in addition to LIKE operator add also simple set matching: in('string1', 'string2'...) for whole string matching. 

So our nodejs code will be like: 

function filterNameLikeLookupStrings(lookupStrings) {
    let sql = '';
    if (lookupStrings && lookupStrings.length) {
        sql += db.prepareQuery('(name in(?)', [lookupStrings]);
        lookupStrings.filter(tp => tp.lastIndexOf('*') === tp.length - 1).forEach((tp, i) => {
            let tpParam = tp.substr(0, tp.length - 1).replace(/([%_#])/g, "#$1") + '%';
            sql += db.prepareQuery(` OR name LIKE ? ESCAPE '#'`, [tpParam]);
        });
        sql += ')';
    }
    return sql;
}
 
where lookupStrings is array and, for instance, can be like:
 
[ 'string1', 'string2', 'string_of_text', 'cr%zy_string', 'string*' ]
 
In this case, last item 'string*' contain wildcard at the and an our backend service will find, in addition to straight matching, also records with fields start with 'string'
 

nodejs, node, js, node.js, node-js, mysql, sql, backend, javascript, sql-like, wildcard