Thread: Regular expressions

Regular expressions

From
"Tumurbaatar S."
Date:
What does this '.{2,}' RE pattern mean?

1. 2 or more of any char
2. 2 or more of same char

I assume the answer is the 1st one. If yes,
how the 2nd's pattern should be look?

Thanks.

P.S.
I'm going to use CHECKs to make some basic validations of
email and passwords (5-15 chars):

CHECK (length(Email) = length(substring(Email from '.+@.+\..+')))

CHECK (length(Password) = length(substring(Password from
'[0-9_A-Za-z]{5,15}')))

Can anybody suggest shorter (or compatible with other RE engines) variants?
If possible using only Basic RE or if not, using ERE, but not ARE.


Re: Regular expressions

From
Tom Lane
Date:
"Tumurbaatar S." <tumurbaatar@datacom.mn> writes:
> 2. 2 or more of same char
> how the 2nd's pattern should be look?

I think you need a back reference:

regression=# select 'abc' ~ '(.)\\1';
 ?column?
----------
 f
(1 row)

regression=# select 'abb' ~ '(.)\\1';
 ?column?
----------
 t
(1 row)

            regards, tom lane