How can I execute an SQL SELECT with a LIKE clause for a string containing an open parenthesis character?

I have a simple search query:

<cfquery name="_qSearch" dbtype="Query">
    SELECT 
        *
    FROM    MyQoQ
    WHERE
        DESCRIPTION LIKE '%#URL.searchString#%'
</cfquery>

This query works fine for most values. However, if someone searches for a value like this "xxx[en", they bomb the error message The pattern of the LIKE conditional is malformed..

Is there any way around this, since a bracket is used in CFQUERY?

+3
source share
1 answer

QoQ shares a TSQL (MS SQL Server) function in which it is not simple %and _is wildcard in LIKE - it also supports regex-style character classes, as in [a-z]any lowercase letter.

, , .. [[] [, , , , , % _ - :

'%#Url.SearchString.replaceAll('[\[%_]','[$0]')#%'

( String.replaceAll), [ % _ [.. ] - $0 .

+8

All Articles