0

I was developing a RegEx to use in Posgresql using C# as a test. When I included the RegEx in a Postgresql query. It doesn't work.

Why doesn't this return rows that have "titulo" column of something like "Produto one", "Produto two" and etc. Forgive me if my mistake is a silly one but I am really lost, can't understand why it is not working.

select * from produto where titulo like '(?=[Produto]{6,7})P?r?o?d?u?t?o'

I've also tried.

 select * from produto where titulo like '%(?=[Produto]{6,7})P?r?o?d?u?t?o%'

I've defined the "titulo" column as char(100)

Diego Alves
  • 2,462
  • 3
  • 32
  • 65
  • 3
    When using `like` you are not using a regex. Use `WHERE titulo ~ '(?=[Produto]{6,7})P?r?o?d?u?t?o'` – Wiktor Stribiżew Mar 20 '18 at 14:00
  • 2
    [As documented in the manual](https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-LIKE) `LIKE` does not support regular expressions. –  Mar 20 '18 at 14:05
  • Apart from the comments above, I'm not sure your regex does what you want it to do. The square brackets `[]` define a character class and you've repeated the character `o` in that class. At most the lookahead will find 6-7 occurrences of any character(s) in that class. – David Faber Mar 20 '18 at 14:09
  • so LIKE is not used for Regex. That's the first time I write a query that doesn't look for an exact string. The '%' made think that I could toss any RegEx rule as the argument for the Like Clause. I solved the problem I checked the docs. – Diego Alves Mar 20 '18 at 14:30

0 Answers0