'How to use SIMILAR TO or Posix in Knex for Postgres?
Postgres supports SIMILAR TO and POSIX regular expressions allowing writing more powerful regular expressions than the LIKE operator does. https://www.postgresql.org/docs/7.3/functions-matching.html
I am using Knex to run queries on a Postgres database.
I know how to use LIKE with knex but I could not find the support for SIMILAR TO or POSIX regular expressions.
How can I use SIMILAR TO with knex or even better the POSIX expressions?
Solution 1:[1]
I found the support for POSIX. It seems the SIMILAR TO operator is not supported. However, that is okay as POSIX allows to write more powerful regex than SIMILAR TO.
.where('column', '~', 'pattern');
~: case sensitive match
~*: case-insensitive match
!~ and !~* negation of the corresponding operator.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Berkay Berabi |
