Pregunta

I want to search for a string pattern in a database table.

The search pattern is simply the string entered by the user. However the field to be searched can have spaces in between, or user might enter spaces in the string.

So I want to create a regex, such that if say the string is "Test", I look for regex which might have spaces in between, something like this

T[\s]*e[\s]*s[\s]*t.

Can anyone please suggest how I can do this in Entity framework - or by using ESQL?

¿Fue útil?

Solución

For that pattern, you don't need a Regex. You're best off trimming them out, then doing the search. You could so something like:

SELECT * FROM MyTable
WHERE REPLACE(MyColumn, ' ', '') LIKE '%' + REPLACE(@YourVariable, ' ', '') + '%'
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top