From 311bcfc6b3acdd6fd152798c7f287ddf74fa2a98 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 16 Apr 2024 21:46:48 +0200 Subject: Adding upstream version 15.4. Signed-off-by: Daniel Baumann --- src/test/regress/sql/regex.sql | 158 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/test/regress/sql/regex.sql (limited to 'src/test/regress/sql/regex.sql') diff --git a/src/test/regress/sql/regex.sql b/src/test/regress/sql/regex.sql new file mode 100644 index 0000000..5621710 --- /dev/null +++ b/src/test/regress/sql/regex.sql @@ -0,0 +1,158 @@ +-- +-- 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*(?