SUBSTRING_INDEX with REGEX

1

How can I do a search for the last name of a people but with a regular expression?

Today I use SUBSTRING_INDEX to get the last name , but I want to get parts of this last name when I search by name or fragments of people I am using REGEXP that calls a function of mine that creates a regular expression. When I try to use SUBSTRING_INDEX with REGEXP it will not stop right.

I use cakePHP to develop.

The command line below:

 $filtros = array_merge($filtros, array("SUBSTRING_INDEX(Usuario.nome, ' ', 1) = 'REGEXP \"".$this->stringParaBusca($criterios["criteriaPrimeiroNome"])."\"'"));
    
asked by anonymous 11.04.2014 / 16:44

1 answer

1

The function REGEXP returns 1 if it finds something, and 0 if it does not find it. So in this case you can not use the = comparer, you need to change the query like this:

... WHERE SUBSTRING_INDEX(Usuario.nome, ' ', 1) REGEXP 'sua_regex'
    
11.04.2014 / 20:31