WITH t AS ( SELECT 'file.txt' file_name UNION ALL SELECT 'file (1).txt' UNION ALL SELECT 'wefile.txt' UNION ALL SELECT 'wefile (1).txt' UNION ALL SELECT 'file (2).txt' UNION ALL SELECT 'file-service.txt' UNION ALL SELECT 'file-service (1).txt' ) SELECT file_name FROM t a , (SELECT 'file' prefix, '.txt' extension) b WHERE REGEXP_INSTR(file_name, CONCAT('^', prefix, ' [(][0-9]+[)]', extension, '$')) = 1 ;