SUBSTRING_INDEX with REGEX

Asked

Viewed 84 times

1

It has as I make a search of the last name of a people but with regular expression?

Today I use the SUBSTRING_INDEX to catch the last name, the more I want to take parts of this last name, when I search by name or name fragments of people I am using the REGEXP calling a function of mine that creates a regular expression. When I try to use the SUBSTRING_INDEX with the REGEXP stop not very sure not.

Using cakephp to develop.

The command line below:

 $filtros = array_merge($filtros, array("SUBSTRING_INDEX(Usuario.nome, ' ', 1) = 'REGEXP \"".$this->stringParaBusca($criterios["criteriaPrimeiroNome"])."\"'"));

1 answer

1

The function REGEXP returns 1 if they find anything, and 0 if not find. Therefore in that case you cannot use the comparator =, need to change the query thus:

... WHERE SUBSTRING_INDEX(Usuario.nome, ' ', 1) REGEXP 'sua_regex'
  • I was able to solve, I just took the "=" really, thank you.

  • @Jeremiaspereira accept the answer of our colleague then...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.