USING: regexp tools.test kernel sequences regexp.parser regexp.traversal eval ; IN: regexp-tests [ f ] [ "b" "a*" matches? ] unit-test [ t ] [ "" "a*" matches? ] unit-test [ t ] [ "a" "a*" matches? ] unit-test [ t ] [ "aaaaaaa" "a*" matches? ] unit-test [ f ] [ "ab" "a*" matches? ] unit-test [ t ] [ "abc" "abc" matches? ] unit-test [ t ] [ "a" "a|b|c" matches? ] unit-test [ t ] [ "b" "a|b|c" matches? ] unit-test [ t ] [ "c" "a|b|c" matches? ] unit-test [ f ] [ "c" "d|e|f" matches? ] unit-test [ t ] [ "b" "|b" matches? ] unit-test [ t ] [ "b" "b|" matches? ] unit-test [ t ] [ "" "b|" matches? ] unit-test [ t ] [ "" "b|" matches? ] unit-test [ f ] [ "" "|" matches? ] unit-test [ f ] [ "" "|||||||" matches? ] unit-test [ f ] [ "aa" "a|b|c" matches? ] unit-test [ f ] [ "bb" "a|b|c" matches? ] unit-test [ f ] [ "cc" "a|b|c" matches? ] unit-test [ f ] [ "cc" "d|e|f" matches? ] unit-test [ f ] [ "" "a+" matches? ] unit-test [ t ] [ "a" "a+" matches? ] unit-test [ t ] [ "aa" "a+" matches? ] unit-test [ t ] [ "" "a?" matches? ] unit-test [ t ] [ "a" "a?" matches? ] unit-test [ f ] [ "aa" "a?" matches? ] unit-test [ f ] [ "" "." matches? ] unit-test [ t ] [ "a" "." matches? ] unit-test [ t ] [ "." "." matches? ] unit-test ! [ f ] [ "\n" "." matches? ] unit-test [ f ] [ "" ".+" matches? ] unit-test [ t ] [ "a" ".+" matches? ] unit-test [ t ] [ "ab" ".+" matches? ] unit-test [ t ] [ "" "a|b*|c+|d?" matches? ] unit-test [ t ] [ "a" "a|b*|c+|d?" matches? ] unit-test [ t ] [ "c" "a|b*|c+|d?" matches? ] unit-test [ t ] [ "cc" "a|b*|c+|d?" matches? ] unit-test [ f ] [ "ccd" "a|b*|c+|d?" matches? ] unit-test [ t ] [ "d" "a|b*|c+|d?" matches? ] unit-test [ t ] [ "foo" "foo|bar" matches? ] unit-test [ t ] [ "bar" "foo|bar" matches? ] unit-test [ f ] [ "foobar" "foo|bar" matches? ] unit-test [ f ] [ "" "(a)" matches? ] unit-test [ t ] [ "a" "(a)" matches? ] unit-test [ f ] [ "aa" "(a)" matches? ] unit-test [ t ] [ "aa" "(a*)" matches? ] unit-test [ f ] [ "aababaaabbac" "(a|b)+" matches? ] unit-test [ t ] [ "ababaaabba" "(a|b)+" matches? ] unit-test [ f ] [ "" "a{1}" matches? ] unit-test [ t ] [ "a" "a{1}" matches? ] unit-test [ f ] [ "aa" "a{1}" matches? ] unit-test [ f ] [ "a" "a{2,}" matches? ] unit-test [ t ] [ "aaa" "a{2,}" matches? ] unit-test [ t ] [ "aaaa" "a{2,}" matches? ] unit-test [ t ] [ "aaaaa" "a{2,}" matches? ] unit-test [ t ] [ "" "a{,2}" matches? ] unit-test [ t ] [ "a" "a{,2}" matches? ] unit-test [ t ] [ "aa" "a{,2}" matches? ] unit-test [ f ] [ "aaa" "a{,2}" matches? ] unit-test [ f ] [ "aaaa" "a{,2}" matches? ] unit-test [ f ] [ "aaaaa" "a{,2}" matches? ] unit-test [ f ] [ "" "a{1,3}" matches? ] unit-test [ t ] [ "a" "a{1,3}" matches? ] unit-test [ t ] [ "aa" "a{1,3}" matches? ] unit-test [ t ] [ "aaa" "a{1,3}" matches? ] unit-test [ f ] [ "aaaa" "a{1,3}" matches? ] unit-test [ f ] [ "" "[a]" matches? ] unit-test [ t ] [ "a" "[a]" matches? ] unit-test [ t ] [ "a" "[abc]" matches? ] unit-test [ f ] [ "b" "[a]" matches? ] unit-test [ f ] [ "d" "[abc]" matches? ] unit-test [ t ] [ "ab" "[abc]{1,2}" matches? ] unit-test [ f ] [ "abc" "[abc]{1,2}" matches? ] unit-test [ f ] [ "" "[^a]" matches? ] unit-test [ f ] [ "a" "[^a]" matches? ] unit-test [ f ] [ "a" "[^abc]" matches? ] unit-test [ t ] [ "b" "[^a]" matches? ] unit-test [ t ] [ "d" "[^abc]" matches? ] unit-test [ f ] [ "ab" "[^abc]{1,2}" matches? ] unit-test [ f ] [ "abc" "[^abc]{1,2}" matches? ] unit-test [ t ] [ "]" "[]]" matches? ] unit-test [ f ] [ "]" "[^]]" matches? ] unit-test [ t ] [ "a" "[^]]" matches? ] unit-test [ "^" "[^]" matches? ] must-fail [ t ] [ "^" "[]^]" matches? ] unit-test [ t ] [ "]" "[]^]" matches? ] unit-test [ t ] [ "[" "[[]" matches? ] unit-test [ f ] [ "^" "[^^]" matches? ] unit-test [ t ] [ "a" "[^^]" matches? ] unit-test [ t ] [ "-" "[-]" matches? ] unit-test [ f ] [ "a" "[-]" matches? ] unit-test [ f ] [ "-" "[^-]" matches? ] unit-test [ t ] [ "a" "[^-]" matches? ] unit-test [ t ] [ "-" "[-a]" matches? ] unit-test [ t ] [ "a" "[-a]" matches? ] unit-test [ t ] [ "-" "[a-]" matches? ] unit-test [ t ] [ "a" "[a-]" matches? ] unit-test [ f ] [ "b" "[a-]" matches? ] unit-test [ f ] [ "-" "[^-]" matches? ] unit-test [ t ] [ "a" "[^-]" matches? ] unit-test [ f ] [ "-" "[a-c]" matches? ] unit-test [ t ] [ "-" "[^a-c]" matches? ] unit-test [ t ] [ "b" "[a-c]" matches? ] unit-test [ f ] [ "b" "[^a-c]" matches? ] unit-test [ t ] [ "-" "[a-c-]" matches? ] unit-test [ f ] [ "-" "[^a-c-]" matches? ] unit-test [ t ] [ "\\" "[\\\\]" matches? ] unit-test [ f ] [ "a" "[\\\\]" matches? ] unit-test [ f ] [ "\\" "[^\\\\]" matches? ] unit-test [ t ] [ "a" "[^\\\\]" matches? ] unit-test [ t ] [ "0" "[\\d]" matches? ] unit-test [ f ] [ "a" "[\\d]" matches? ] unit-test [ f ] [ "0" "[^\\d]" matches? ] unit-test [ t ] [ "a" "[^\\d]" matches? ] unit-test [ t ] [ "a" "[a-z]{1,}|[A-Z]{2,4}|b*|c|(f|g)*" matches? ] unit-test [ t ] [ "a" "[a-z]{1,2}|[A-Z]{3,3}|b*|c|(f|g)*" matches? ] unit-test [ t ] [ "a" "[a-z]{1,2}|[A-Z]{3,3}" matches? ] unit-test [ t ] [ "1000" "\\d{4,6}" matches? ] unit-test [ t ] [ "1000" "[0-9]{4,6}" matches? ] unit-test [ t ] [ "abc" "\\p{Lower}{3}" matches? ] unit-test [ f ] [ "ABC" "\\p{Lower}{3}" matches? ] unit-test [ t ] [ "ABC" "\\p{Upper}{3}" matches? ] unit-test [ f ] [ "abc" "\\p{Upper}{3}" matches? ] unit-test ! [ f ] [ "abc" "[\\p{Upper}]{3}" matches? ] unit-test [ t ] [ "ABC" "[\\p{Upper}]{3}" matches? ] unit-test [ f ] [ "" "\\Q\\E" matches? ] unit-test [ f ] [ "a" "\\Q\\E" matches? ] unit-test [ t ] [ "|*+" "\\Q|*+\\E" matches? ] unit-test [ f ] [ "abc" "\\Q|*+\\E" matches? ] unit-test [ t ] [ "s" "\\Qs\\E" matches? ] unit-test [ t ] [ "S" "\\0123" matches? ] unit-test [ t ] [ "SXY" "\\0123XY" matches? ] unit-test [ t ] [ "x" "\\x78" matches? ] unit-test [ f ] [ "y" "\\x78" matches? ] unit-test [ t ] [ "x" "\\u000078" matches? ] unit-test [ f ] [ "y" "\\u000078" matches? ] unit-test [ t ] [ "ab" "a+b" matches? ] unit-test [ f ] [ "b" "a+b" matches? ] unit-test [ t ] [ "aab" "a+b" matches? ] unit-test [ f ] [ "abb" "a+b" matches? ] unit-test [ t ] [ "abbbb" "ab*" matches? ] unit-test [ t ] [ "a" "ab*" matches? ] unit-test [ f ] [ "abab" "ab*" matches? ] unit-test [ f ] [ "x" "\\." matches? ] unit-test [ t ] [ "." "\\." matches? ] unit-test [ t ] [ "aaaab" "a+ab" matches? ] unit-test [ f ] [ "aaaxb" "a+ab" matches? ] unit-test [ t ] [ "aaacb" "a+cb" matches? ] unit-test [ 3 ] [ "aaacb" "a*" match-head ] unit-test [ 2 ] [ "aaacb" "aa?" match-head ] unit-test [ t ] [ "aaa" "AAA" matches? ] unit-test [ f ] [ "aax" "AAA" matches? ] unit-test [ t ] [ "aaa" "A*" matches? ] unit-test [ f ] [ "aaba" "A*" matches? ] unit-test [ t ] [ "b" "[AB]" matches? ] unit-test [ f ] [ "c" "[AB]" matches? ] unit-test [ t ] [ "c" "[A-Z]" matches? ] unit-test [ f ] [ "3" "[A-Z]" matches? ] unit-test [ t ] [ "a" "(?i)a" matches? ] unit-test [ t ] [ "a" "(?i)a" matches? ] unit-test [ t ] [ "A" "(?i)a" matches? ] unit-test [ t ] [ "A" "(?i)a" matches? ] unit-test [ t ] [ "a" "(?-i)a" matches? ] unit-test [ t ] [ "a" "(?-i)a" matches? ] unit-test [ f ] [ "A" "(?-i)a" matches? ] unit-test [ f ] [ "A" "(?-i)a" matches? ] unit-test [ f ] [ "A" "[a-z]" matches? ] unit-test [ t ] [ "A" "[a-z]" matches? ] unit-test [ f ] [ "A" "\\p{Lower}" matches? ] unit-test [ t ] [ "A" "\\p{Lower}" matches? ] unit-test [ t ] [ "abc" "abc" matches? ] unit-test [ t ] [ "abc" "a[bB][cC]" matches? ] unit-test [ t ] [ "adcbe" "a(?r)(bcd)(?-r)e" matches? ] unit-test [ t ] [ "s@f" "[a-z.-]@[a-z]" matches? ] unit-test [ f ] [ "a" "[a-z.-]@[a-z]" matches? ] unit-test [ t ] [ ".o" "\\.[a-z]" matches? ] unit-test [ t ] [ "abc*" "[^\\*]*\\*" matches? ] unit-test [ t ] [ "bca" "[^a]*a" matches? ] unit-test [ ] [ "(0[lL]?|[1-9]\\d{0,9}(\\d{0,9}[lL])?|0[xX]\\p{XDigit}{1,8}(\\p{XDigit}{0,8}[lL])?|0[0-7]{1,11}([0-7]{0,11}[lL])?|([0-9]+\\.[0-9]*|\\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?|[0-9]+([eE][+-]?[0-9]+[fFdD]?|([eE][+-]?[0-9]+)?[fFdD]))" drop ] unit-test [ ] [ "(\\$[\\p{XDigit}]|[\\p{Digit}])" drop ] unit-test ! Comment [ t ] [ "ac" "a(?#boo)c" matches? ] unit-test ! [ "{Lower}" ] [ invalid-range? ] must-fail-with ! [ 1 ] [ "aaacb" "a+?" match-head ] unit-test ! [ 1 ] [ "aaacb" "aa??" match-head ] unit-test ! [ f ] [ "aaaab" "a++ab" matches? ] unit-test ! [ t ] [ "aaacb" "a++cb" matches? ] unit-test ! [ 3 ] [ "aacb" "aa?c" match-head ] unit-test ! [ 3 ] [ "aacb" "aa??c" match-head ] unit-test ! [ t ] [ "fxxbar" "(?!foo).{3}bar" matches? ] unit-test ! [ f ] [ "foobar" "(?!foo).{3}bar" matches? ] unit-test [ 3 ] [ "foobar" "foo(?=bar)" match-head ] unit-test [ f ] [ "foobxr" "foo(?=bar)" match-head ] unit-test ! [ f ] [ "foobxr" "foo\\z" match-head ] unit-test ! [ 3 ] [ "foo" "foo\\z" match-head ] unit-test ! [ 3 ] [ "foo bar" "foo\\b" match-head ] unit-test ! [ f ] [ "fooxbar" "foo\\b" matches? ] unit-test ! [ t ] [ "foo" "foo\\b" matches? ] unit-test ! [ t ] [ "foo bar" "foo\\b bar" matches? ] unit-test ! [ f ] [ "fooxbar" "foo\\bxbar" matches? ] unit-test ! [ f ] [ "foo" "foo\\bbar" matches? ] unit-test ! [ f ] [ "foo bar" "foo\\B" matches? ] unit-test ! [ 3 ] [ "fooxbar" "foo\\B" match-head ] unit-test ! [ t ] [ "foo" "foo\\B" matches? ] unit-test ! [ f ] [ "foo bar" "foo\\B bar" matches? ] unit-test ! [ t ] [ "fooxbar" "foo\\Bxbar" matches? ] unit-test ! [ f ] [ "foo" "foo\\Bbar" matches? ] unit-test [ ] [ "USING: regexp kernel ; R' -{3}[+]{1,6}(?:!!)?\\s' drop" eval ] unit-test [ ] [ "USING: regexp kernel ; R' (ftp|http|https)://(\\w+:?\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?' drop" eval ] unit-test [ ] [ "USING: regexp kernel ; R' \\*[^\s*][^*]*\\*' drop" eval ] unit-test ! Bug in parsing word ! [ t ] [ "a" R' a' matches? ] unit-test ! ((A)(B(C))) ! 1. ((A)(B(C))) ! 2. (A) ! 3. (B(C)) ! 4. (C) ! clear "a(?=b*)" "ab" over match ! clear "a(?=b*c)" "abbbbbc" over match ! clear "a(?=b*)" "ab" over match ! clear "^a" "a" over match ! clear "^a" "\na" over match ! clear "^a" "\r\na" over match ! clear "^a" "\ra" over match ! clear "a$" "a" over match ! clear "a$" "a\n" over match ! clear "a$" "a\r" over match ! clear "a$" "a\r\n" over match ! "(az)(?<=b)" "baz" over first-match ! "a(?<=b*)" "cbaz" over first-match ! "a(?<=b)" "baz" over first-match ! "a(? "baz" over first-match ! "a(? "caz" over first-match ! "a(?=bcdefg)bcd" "abcdefg" over first-match ! "a(?#bcdefg)bcd" "abcdefg" over first-match ! "a(?:bcdefg)" "abcdefg" over first-match [ { 0 1 } ] [ "ac" "a(?!b)" first-match ] unit-test [ f ] [ "ab" "a(?!b)" first-match ] unit-test ! "a(?<=b)" "caba" over first-match [ { 0 1 } ] [ "ab" "a(?=b)(?=b)" first-match ] unit-test [ { 1 2 } ] [ "ba" "a(?<=b)(?<=b)" first-match ] unit-test [ { 1 2 } ] [ "cab" "a(?=b)(?<=c)" first-match ] unit-test ! capture group 1: "aaaa" 2: "" ! "aaaa" "(a*)(a*)" match* ! "aaaa" "(a*)(a+)" match* [ { 0 2 } ] [ "ab" "(a|ab)(bc)?" first-match ] unit-test [ { 0 3 } ] [ "abc" "(a|ab)(bc)?" first-match ] unit-test [ { 0 2 } ] [ "ab" "(ab|a)(bc)?" first-match ] unit-test [ { 0 3 } ] [ "abc" "(ab|a)(bc)?" first-match ] unit-test [ { 23 24 } ] [ "aaaaaaaaaaaaaaaaaaaaaaab" "((a*)*b)*b" first-match ] unit-test