-- -- Regular expression tests -- -- Don't want to have to double backslashes in regexes set standard_conforming_strings = on; -- Test simple quantified backrefs select 'bbbbb' ~ '^([bc])\1*$' as t; select 'ccc' ~ '^([bc])\1*$' as t; select 'xxx' ~ '^([bc])\1*$' as f; select 'bbc' ~ '^([bc])\1*$' as f; select 'b' ~ '^([bc])\1*$' as t; -- Test quantified backref within a larger expression select 'abc abc abc' ~ '^(\w+)( \1)+$' as t; select 'abc abd abc' ~ '^(\w+)( \1)+$' as f; select 'abc abc abd' ~ '^(\w+)( \1)+$' as f; select 'abc abc abc' ~ '^(.+)( \1)+$' as t; select 'abc abd abc' ~ '^(.+)( \1)+$' as f; select 'abc abc abd' ~ '^(.+)( \1)+$' as f; -- Test some cases that crashed in 9.2beta1 due to pmatch[] array overrun select substring('asd TO foo' from ' TO (([a-z0-9._]+|"([^"]+|"")+")+)'); select substring('a' from '((a))+'); select substring('a' from '((a)+)'); -- Test regexp_match() select regexp_match('abc', ''); select regexp_match('abc', 'bc'); select regexp_match('abc', 'd') is null; select regexp_match('abc', '(B)(c)', 'i'); select regexp_match('abc', 'Bd', 'ig'); -- error -- Test lookahead constraints select regexp_matches('ab', 'a(?=b)b*'); select regexp_matches('a', 'a(?=b)b*'); select regexp_matches('abc', 'a(?=b)b*(?=c)c*'); select regexp_matches('ab', 'a(?=b)b*(?=c)c*'); select regexp_matches('ab', 'a(?!b)b*'); select regexp_matches('a', 'a(?!b)b*'); select regexp_matches('b', '(?=b)b'); select regexp_matches('a', '(?=b)b'); -- Test lookbehind constraints select regexp_matches('abb', '(?<=a)b*'); select regexp_matches('a', 'a(?<=a)b*'); select regexp_matches('abc', 'a(?<=a)b*(?<=b)c*'); select regexp_matches('ab', 'a(?<=a)b*(?<=b)c*'); select regexp_matches('ab', 'a*(?