User1920
User1920

Reputation: 57

SQL or regular expression to match strings whose end is like the beginning, but in reverse

I have the query select * from tbl where column like '%DEF%'.

Would it be possible to use regular expression to have the characters before DEF be the same as those in the end but in reverse?

An example matching result ASDEFSAor TERDEFRET?

Upvotes: 2

Views: 115

Answers (1)

Mureinik
Mureinik

Reputation: 311103

This can be done with a combination of reverse and replace:

SELECT *
FROM   tbl
WHERE  col LIKE '%DEF%' AND
       REPLACE(col, 'DEF', '') = REVERSE(REPLACE(col, 'DEF', ''))

Upvotes: 4

Related Questions