I have a data store having a Note field (a textarea) and want to display all Notes satisfying a user input (even metacharacters).

I've written the following function to handle this:

    function notefilter() {
        var newfilter = Ext.getCmp('searchnote');
        var searchStr = newfilter.getValue();
        searchStr = searchStr.replace('?', '\\?').replace('*', '\\*').replace('+', '\\+').replace('{', '\\{').replace('}', '\\}').replace('[', '\\[').replace(']', '\\]').replace('(', '\\(').replace(')', '\\)').replace('|', '\\|').replace('$', '\\$').replace('^', '\\^');

        var re = new RegExp(".*" + searchStr + ".*", "ig");
        Ext.getCmp('notesgrid').store.filter('Note', re);
    }

However the filter fails to search for metacharacters even after escaping them, but it works are all other alphanumeric input.

Am I missing something ?

Thanks in advance !

Have you looked at the JS built-ins 'escape()' and 'unescape()'?

Thanks the hint. You saved my day. escape() did the work for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.