repeated characters in SQL

From: Govind Chettiar <rashapoo(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: repeated characters in SQL
Date: 2016-01-23 23:44:00
Message-ID: CAFH6Zn+eu7LnmRcobcRS-5OoEPMjrDGqNTW08z-k81AfNQStdw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a simple table consisting of a bunch of English words. I am trying
to find words that have repeated characters in them, for example
apple
tattoo

but not

orange
lemon

I know that only a maximum of one repetition can occur

I tried various options like
SELECT word FROM public."SpellItWords"
WHERE word ~ E'(.)\1{2,}'

SELECT word FROM public."SpellItWords"
WHERE word ~ E'([a-z])\1{2}'

What finally worked was this
SELECT word FROM public."SpellItWords"
WHERE word ~ E'(.)\\1'

But I don't really understand what this does...Can you explain?

Thanks!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2016-01-23 23:47:00 Re: A motion
Previous Message Joshua D. Drake 2016-01-23 23:43:11 Re: Let's Do the CoC Right