|
|
|
@ -7,177 +7,184 @@ import (
|
|
|
|
|
|
|
|
|
|
var reTests = []struct {
|
|
|
|
|
re string
|
|
|
|
|
flags []ReFlag
|
|
|
|
|
str string
|
|
|
|
|
result []Group // Stores all zero-groups in the match
|
|
|
|
|
}{
|
|
|
|
|
{"a", "abc", []Group{{0, 1}}},
|
|
|
|
|
{"a", "bca", []Group{{2, 3}}},
|
|
|
|
|
{"l", "ggllgg", []Group{{2, 3}, {3, 4}}},
|
|
|
|
|
{"(b|c)", "abdceb", []Group{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
|
{"a+", "brerereraaaaabbbbb", []Group{{8, 13}}},
|
|
|
|
|
{"ab+", "qweqweqweaqweqweabbbbbr", []Group{{16, 22}}},
|
|
|
|
|
{"(b|c|A)", "ooaoobocA", []Group{{5, 6}, {7, 8}, {8, 9}}},
|
|
|
|
|
{"ab*", "a", []Group{{0, 1}}},
|
|
|
|
|
{"ab*", "abb", []Group{{0, 3}}},
|
|
|
|
|
{"a*b", "aaab", []Group{{0, 4}}},
|
|
|
|
|
{"a*b", "qwqw", []Group{}},
|
|
|
|
|
{"(abc)*", "abcabcabc", []Group{{0, 9}, {9, 9}}},
|
|
|
|
|
{"((abc)|(def))*", "abcdef", []Group{{0, 6}, {6, 6}}},
|
|
|
|
|
{"(abc)*|(def)*", "abcdef", []Group{{0, 3}, {3, 6}, {6, 6}}},
|
|
|
|
|
{"b*a*a", "bba", []Group{{0, 3}}},
|
|
|
|
|
{"(ab)+", "abcabddd", []Group{{0, 2}, {3, 5}}},
|
|
|
|
|
{"a(b(c|d)*)*", "abccbd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)*d+", "abccdd", []Group{{0, 6}}},
|
|
|
|
|
{"a*", "", []Group{{0, 0}}},
|
|
|
|
|
{"a|b", "c", []Group{}},
|
|
|
|
|
{"(a|b)*c", "aabbc", []Group{{0, 5}}},
|
|
|
|
|
{"a(b|b)", "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a*", "aaaaaaaa", []Group{{0, 8}, {8, 8}}},
|
|
|
|
|
{"a", nil, "abc", []Group{{0, 1}}},
|
|
|
|
|
{"a", nil, "bca", []Group{{2, 3}}},
|
|
|
|
|
{"l", nil, "ggllgg", []Group{{2, 3}, {3, 4}}},
|
|
|
|
|
{"(b|c)", nil, "abdceb", []Group{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
|
{"a+", nil, "brerereraaaaabbbbb", []Group{{8, 13}}},
|
|
|
|
|
{"ab+", nil, "qweqweqweaqweqweabbbbbr", []Group{{16, 22}}},
|
|
|
|
|
{"(b|c|A)", nil, "ooaoobocA", []Group{{5, 6}, {7, 8}, {8, 9}}},
|
|
|
|
|
{"ab*", nil, "a", []Group{{0, 1}}},
|
|
|
|
|
{"ab*", nil, "abb", []Group{{0, 3}}},
|
|
|
|
|
{"a*b", nil, "aaab", []Group{{0, 4}}},
|
|
|
|
|
{"a*b", nil, "qwqw", []Group{}},
|
|
|
|
|
{"(abc)*", nil, "abcabcabc", []Group{{0, 9}, {9, 9}}},
|
|
|
|
|
{"((abc)|(def))*", nil, "abcdef", []Group{{0, 6}, {6, 6}}},
|
|
|
|
|
{"(abc)*|(def)*", nil, "abcdef", []Group{{0, 3}, {3, 6}, {6, 6}}},
|
|
|
|
|
{"b*a*a", nil, "bba", []Group{{0, 3}}},
|
|
|
|
|
{"(ab)+", nil, "abcabddd", []Group{{0, 2}, {3, 5}}},
|
|
|
|
|
{"a(b(c|d)*)*", nil, "abccbd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)*d+", nil, "abccdd", []Group{{0, 6}}},
|
|
|
|
|
{"a*", nil, "", []Group{{0, 0}}},
|
|
|
|
|
{"a|b", nil, "c", []Group{}},
|
|
|
|
|
{"(a|b)*c", nil, "aabbc", []Group{{0, 5}}},
|
|
|
|
|
{"a(b|b)", nil, "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a*", nil, "aaaaaaaa", []Group{{0, 8}, {8, 8}}},
|
|
|
|
|
|
|
|
|
|
{"ab?", "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a?b", "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a?", "", []Group{{0, 0}}},
|
|
|
|
|
{"a?b?c", "a", []Group{}},
|
|
|
|
|
{"a?b?c?", "ab", []Group{{0, 2}, {2, 2}}},
|
|
|
|
|
{"a?b?c?", "ac", []Group{{0, 2}, {2, 2}}},
|
|
|
|
|
{"a?b?c", "abc", []Group{{0, 3}}},
|
|
|
|
|
{"a?b?c", "acb", []Group{{0, 2}}},
|
|
|
|
|
{"ab?", nil, "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a?b", nil, "ab", []Group{{0, 2}}},
|
|
|
|
|
{"a?", nil, "", []Group{{0, 0}}},
|
|
|
|
|
{"a?b?c", nil, "a", []Group{}},
|
|
|
|
|
{"a?b?c?", nil, "ab", []Group{{0, 2}, {2, 2}}},
|
|
|
|
|
{"a?b?c?", nil, "ac", []Group{{0, 2}, {2, 2}}},
|
|
|
|
|
{"a?b?c", nil, "abc", []Group{{0, 3}}},
|
|
|
|
|
{"a?b?c", nil, "acb", []Group{{0, 2}}},
|
|
|
|
|
|
|
|
|
|
{"[abc]", "defadefbdefce", []Group{{3, 4}, {7, 8}, {11, 12}}},
|
|
|
|
|
{"[ab]c", "ab", []Group{}},
|
|
|
|
|
{"g[ab]c", "gac", []Group{{0, 3}}},
|
|
|
|
|
{"g[ab]c", "gbc", []Group{{0, 3}}},
|
|
|
|
|
{"g[ab]c", "gc", []Group{}},
|
|
|
|
|
{"g[ab]c", "gfc", []Group{}},
|
|
|
|
|
{"[ab]*", "aabbbabaababab", []Group{{0, 14}, {14, 14}}},
|
|
|
|
|
{"[ab]+", "aabbbablaababab", []Group{{0, 7}, {8, 15}}},
|
|
|
|
|
{"[Ff]r[Uu]it", "fruit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu]it", "FrUit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu|]it", "Fr|it", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r([Uu]|[pP])it", "Frpit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu]|[pP]it", "Frpit", []Group{{2, 5}}},
|
|
|
|
|
{"[a-zA-Z]+", "Hello, how is it going?", []Group{{0, 5}, {7, 10}, {11, 13}, {14, 16}, {17, 22}}},
|
|
|
|
|
{"[abc]", nil, "defadefbdefce", []Group{{3, 4}, {7, 8}, {11, 12}}},
|
|
|
|
|
{"[ab]c", nil, "ab", []Group{}},
|
|
|
|
|
{"g[ab]c", nil, "gac", []Group{{0, 3}}},
|
|
|
|
|
{"g[ab]c", nil, "gbc", []Group{{0, 3}}},
|
|
|
|
|
{"g[ab]c", nil, "gc", []Group{}},
|
|
|
|
|
{"g[ab]c", nil, "gfc", []Group{}},
|
|
|
|
|
{"[ab]*", nil, "aabbbabaababab", []Group{{0, 14}, {14, 14}}},
|
|
|
|
|
{"[ab]+", nil, "aabbbablaababab", []Group{{0, 7}, {8, 15}}},
|
|
|
|
|
{"[Ff]r[Uu]it", nil, "fruit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu]it", nil, "FrUit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu|]it", nil, "Fr|it", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r([Uu]|[pP])it", nil, "Frpit", []Group{{0, 5}}},
|
|
|
|
|
{"[Ff]r[Uu]|[pP]it", nil, "Frpit", []Group{{2, 5}}},
|
|
|
|
|
{"[a-zA-Z]+", nil, "Hello, how is it going?", []Group{{0, 5}, {7, 10}, {11, 13}, {14, 16}, {17, 22}}},
|
|
|
|
|
|
|
|
|
|
{".+", "Hello, how is it going?", []Group{{0, 23}}},
|
|
|
|
|
{"a.", "a ", []Group{{0, 2}}},
|
|
|
|
|
{"a.b", "a/b", []Group{{0, 3}}},
|
|
|
|
|
{".", "a ", []Group{{0, 1}, {1, 2}}},
|
|
|
|
|
{"a.", "a ", []Group{{0, 2}}},
|
|
|
|
|
{".+b", "abc", []Group{{0, 2}}},
|
|
|
|
|
{".+", nil, "Hello, how is it going?", []Group{{0, 23}}},
|
|
|
|
|
{"a.", nil, "a ", []Group{{0, 2}}},
|
|
|
|
|
{"a.b", nil, "a/b", []Group{{0, 3}}},
|
|
|
|
|
{".", nil, "a ", []Group{{0, 1}, {1, 2}}},
|
|
|
|
|
{"a.", nil, "a ", []Group{{0, 2}}},
|
|
|
|
|
{".+b", nil, "abc", []Group{{0, 2}}},
|
|
|
|
|
|
|
|
|
|
{`\d`, "1a0a3s'''34343s", []Group{{0, 1}, {2, 3}, {4, 5}, {9, 10}, {10, 11}, {11, 12}, {12, 13}, {13, 14}}},
|
|
|
|
|
{`\\`, `a\b\c\qwe\`, []Group{{1, 2}, {3, 4}, {5, 6}, {9, 10}}},
|
|
|
|
|
{`\W`, `"Hello", he said. How are you doing?`, []Group{{0, 1}, {6, 7}, {7, 8}, {8, 9}, {11, 12}, {16, 17}, {17, 18}, {21, 22}, {25, 26}, {29, 30}, {35, 36}}},
|
|
|
|
|
{`\w`, ";';';';';'qwe12", []Group{{10, 11}, {11, 12}, {12, 13}, {13, 14}, {14, 15}}},
|
|
|
|
|
{`\s`, "a b c d", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
|
|
|
|
{`\<`, "<HTML><body>", []Group{{0, 1}, {6, 7}}},
|
|
|
|
|
{`\(.+\)`, "Not (paranthesized), (so) is (this) not", []Group{{4, 35}}},
|
|
|
|
|
{`\d`, nil, "1a0a3s'''34343s", []Group{{0, 1}, {2, 3}, {4, 5}, {9, 10}, {10, 11}, {11, 12}, {12, 13}, {13, 14}}},
|
|
|
|
|
{`\\`, nil, `a\b\c\qwe\`, []Group{{1, 2}, {3, 4}, {5, 6}, {9, 10}}},
|
|
|
|
|
{`\W`, nil, `"Hello", he said. How are you doing?`, []Group{{0, 1}, {6, 7}, {7, 8}, {8, 9}, {11, 12}, {16, 17}, {17, 18}, {21, 22}, {25, 26}, {29, 30}, {35, 36}}},
|
|
|
|
|
{`\w`, nil, ";';';';';'qwe12", []Group{{10, 11}, {11, 12}, {12, 13}, {13, 14}, {14, 15}}},
|
|
|
|
|
{`\s`, nil, "a b c d", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
|
|
|
|
{`\<`, nil, "<HTML><body>", []Group{{0, 1}, {6, 7}}},
|
|
|
|
|
{`\(.+\)`, nil, "Not (paranthesized), (so) is (this) not", []Group{{4, 35}}},
|
|
|
|
|
|
|
|
|
|
{"[^abc]+", "qarbtopsaplpclkpasdmb prejip0r,p", []Group{{0, 1}, {2, 3}, {4, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 32}}},
|
|
|
|
|
{"[^a]+", "qqqaq", []Group{{0, 3}, {4, 5}}},
|
|
|
|
|
{"[^0-9]+", "a1b2c3dd", []Group{{0, 1}, {2, 3}, {4, 5}, {6, 8}}},
|
|
|
|
|
{"[^abc]+", "ababababbababaccacacacaca", []Group{}},
|
|
|
|
|
{`\[`, "a[b[c[]]]", []Group{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
|
{`\([^)]+\)`, "Not (paranthesized), (so) is (this) not", []Group{{4, 19}, {21, 25}, {29, 35}}},
|
|
|
|
|
{"[^abc]+", nil, "qarbtopsaplpclkpasdmb prejip0r,p", []Group{{0, 1}, {2, 3}, {4, 8}, {9, 12}, {13, 16}, {17, 20}, {21, 32}}},
|
|
|
|
|
{"[^a]+", nil, "qqqaq", []Group{{0, 3}, {4, 5}}},
|
|
|
|
|
{"[^0-9]+", nil, "a1b2c3dd", []Group{{0, 1}, {2, 3}, {4, 5}, {6, 8}}},
|
|
|
|
|
{"[^abc]+", nil, "ababababbababaccacacacaca", []Group{}},
|
|
|
|
|
{`\[`, nil, "a[b[c[]]]", []Group{{1, 2}, {3, 4}, {5, 6}}},
|
|
|
|
|
{`\([^)]+\)`, nil, "Not (paranthesized), (so) is (this) not", []Group{{4, 19}, {21, 25}, {29, 35}}},
|
|
|
|
|
|
|
|
|
|
{"^ab", "ab bab", []Group{{0, 2}}},
|
|
|
|
|
{"^aaaa^", "aaaaaaaa", []Group{}},
|
|
|
|
|
{"^([bB][Gg])", "bG", []Group{{0, 2}}},
|
|
|
|
|
{"b$", "ba", []Group{}},
|
|
|
|
|
{"(boy|girl)$", "girlf", []Group{}},
|
|
|
|
|
{`\bint\b`, "print int integer", []Group{{6, 9}}},
|
|
|
|
|
{`int\b`, "ints", []Group{}},
|
|
|
|
|
{`int(\b|a)`, "inta", []Group{{0, 4}}},
|
|
|
|
|
{`\b\d+\b`, "511 a3 43", []Group{{0, 3}, {7, 9}}},
|
|
|
|
|
{`\Bint\B`, "prints int integer print", []Group{{2, 5}}},
|
|
|
|
|
{`^`, "5^3^2", []Group{{0, 0}}},
|
|
|
|
|
{`\^`, "5^3^2", []Group{{1, 2}, {3, 4}}},
|
|
|
|
|
{`pool$`, "pool carpool", []Group{{8, 12}}},
|
|
|
|
|
{`^int$`, "print int integer", []Group{}},
|
|
|
|
|
{`^int$`, "int", []Group{{0, 3}}},
|
|
|
|
|
{`b*`, "aaaaaaaaaaqweqwe", []Group{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}}},
|
|
|
|
|
{"^ab", nil, "ab bab", []Group{{0, 2}}},
|
|
|
|
|
{"^aaaa^", nil, "aaaaaaaa", []Group{}},
|
|
|
|
|
{"^([bB][Gg])", nil, "bG", []Group{{0, 2}}},
|
|
|
|
|
{"b$", nil, "ba", []Group{}},
|
|
|
|
|
{"(boy|girl)$", nil, "girlf", []Group{}},
|
|
|
|
|
{`\bint\b`, nil, "print int integer", []Group{{6, 9}}},
|
|
|
|
|
{`int\b`, nil, "ints", []Group{}},
|
|
|
|
|
{`int(\b|a)`, nil, "inta", []Group{{0, 4}}},
|
|
|
|
|
{`\b\d+\b`, nil, "511 a3 43", []Group{{0, 3}, {7, 9}}},
|
|
|
|
|
{`\Bint\B`, nil, "prints int integer print", []Group{{2, 5}}},
|
|
|
|
|
{`^`, nil, "5^3^2", []Group{{0, 0}}},
|
|
|
|
|
{`\^`, nil, "5^3^2", []Group{{1, 2}, {3, 4}}},
|
|
|
|
|
{`pool$`, nil, "pool carpool", []Group{{8, 12}}},
|
|
|
|
|
{`^int$`, nil, "print int integer", []Group{}},
|
|
|
|
|
{`^int$`, nil, "int", []Group{{0, 3}}},
|
|
|
|
|
{`b*`, nil, "aaaaaaaaaaqweqwe", []Group{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15, 15}, {16, 16}}},
|
|
|
|
|
|
|
|
|
|
{"a{4}", "aabaaa", []Group{}},
|
|
|
|
|
{"ab{5}", "abbbbbab", []Group{{0, 6}}},
|
|
|
|
|
{"(a|b){3,4}", "aba", []Group{{0, 3}}},
|
|
|
|
|
{"(a|b){3,4}", "ababaa", []Group{{0, 4}}},
|
|
|
|
|
{"(bc){5,}", "bcbcbcbcbcbcbcbc", []Group{{0, 16}}},
|
|
|
|
|
{`\d{3,4}`, "1209", []Group{{0, 4}}},
|
|
|
|
|
{`\d{3,4}`, "109", []Group{{0, 3}}},
|
|
|
|
|
{`\d{3,4}`, "5", []Group{}},
|
|
|
|
|
{`\d{3,4}`, "123135", []Group{{0, 4}}},
|
|
|
|
|
{`\d{3,4}`, "89a-0", []Group{}},
|
|
|
|
|
{`\d{3,4}`, "ababab555", []Group{{6, 9}}},
|
|
|
|
|
{`\bpaint\b`, "paints", []Group{}},
|
|
|
|
|
{`\b\w{5}\b`, "paint", []Group{{0, 5}}},
|
|
|
|
|
{`[^\w]`, "abcdef1230[]qq';;'", []Group{{10, 11}, {11, 12}, {14, 15}, {15, 16}, {16, 17}, {17, 18}}},
|
|
|
|
|
{`[^\W]`, "abcdef1230[]qq';;'", []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}, {12, 13}, {13, 14}}},
|
|
|
|
|
{`[\[\]]`, "a[b[l]]", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
|
|
|
|
{"a{4}", nil, "aabaaa", []Group{}},
|
|
|
|
|
{"ab{5}", nil, "abbbbbab", []Group{{0, 6}}},
|
|
|
|
|
{"(a|b){3,4}", nil, "aba", []Group{{0, 3}}},
|
|
|
|
|
{"(a|b){3,4}", nil, "ababaa", []Group{{0, 4}}},
|
|
|
|
|
{"(bc){5,}", nil, "bcbcbcbcbcbcbcbc", []Group{{0, 16}}},
|
|
|
|
|
{`\d{3,4}`, nil, "1209", []Group{{0, 4}}},
|
|
|
|
|
{`\d{3,4}`, nil, "109", []Group{{0, 3}}},
|
|
|
|
|
{`\d{3,4}`, nil, "5", []Group{}},
|
|
|
|
|
{`\d{3,4}`, nil, "123135", []Group{{0, 4}}},
|
|
|
|
|
{`\d{3,4}`, nil, "89a-0", []Group{}},
|
|
|
|
|
{`\d{3,4}`, nil, "ababab555", []Group{{6, 9}}},
|
|
|
|
|
{`\bpaint\b`, nil, "paints", []Group{}},
|
|
|
|
|
{`\b\w{5}\b`, nil, "paint", []Group{{0, 5}}},
|
|
|
|
|
{`[^\w]`, nil, "abcdef1230[]qq';;'", []Group{{10, 11}, {11, 12}, {14, 15}, {15, 16}, {16, 17}, {17, 18}}},
|
|
|
|
|
{`[^\W]`, nil, "abcdef1230[]qq';;'", []Group{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}, {12, 13}, {13, 14}}},
|
|
|
|
|
{`[\[\]]`, nil, "a[b[l]]", []Group{{1, 2}, {3, 4}, {5, 6}, {6, 7}}},
|
|
|
|
|
|
|
|
|
|
// Unicode tests
|
|
|
|
|
{`.+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}},
|
|
|
|
|
{`a.b`, "a²b", []Group{{0, 3}}},
|
|
|
|
|
{`[^a]+`, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}},
|
|
|
|
|
{`.+`, nil, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}},
|
|
|
|
|
{`a.b`, nil, "a²b", []Group{{0, 3}}},
|
|
|
|
|
{`[^a]+`, nil, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 25}}},
|
|
|
|
|
|
|
|
|
|
// Fun experiment - AI-generated tests
|
|
|
|
|
{"(abc|def|ghi)", "abcdefg", []Group{{0, 3}, {3, 6}}},
|
|
|
|
|
{"a(b|c)d", "abcd", []Group{}},
|
|
|
|
|
{"a(b|c)*d", "abcbcd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)+d", "abcbcd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)?d", "abd", []Group{{0, 3}}},
|
|
|
|
|
{".+", "hello world", []Group{{0, 11}}},
|
|
|
|
|
{"a.b", "aXb", []Group{{0, 3}}},
|
|
|
|
|
{"a.*b", "aXb", []Group{{0, 3}}},
|
|
|
|
|
{"a.{2,3}b", "aXXb", []Group{{0, 4}}},
|
|
|
|
|
{"a.{2,}b", "aXXXb", []Group{{0, 5}}},
|
|
|
|
|
{"a.{0,3}b", "ab", []Group{{0, 2}}},
|
|
|
|
|
{"[abc]+", "abcabc", []Group{{0, 6}}},
|
|
|
|
|
{"[a-zA-Z]+", "HelloWorld", []Group{{0, 10}}},
|
|
|
|
|
{"[^abc]+", "defghi", []Group{{0, 6}}},
|
|
|
|
|
{"^hello", "hello world", []Group{{0, 5}}},
|
|
|
|
|
{"world$", "hello world", []Group{{6, 11}}},
|
|
|
|
|
{`\bhello\b`, "hello world", []Group{{0, 5}}},
|
|
|
|
|
{`\Bhello\B`, "hello world", []Group{}},
|
|
|
|
|
{"(hello|world)", "hello world", []Group{{0, 5}, {6, 11}}},
|
|
|
|
|
{"(hello|world)+", "hello world", []Group{{0, 5}, {6, 11}}},
|
|
|
|
|
{"(hello|world)*", "hello world", []Group{{0, 5}, {5, 5}, {6, 11}, {11, 11}}},
|
|
|
|
|
{"(hello|world)?", "hello world", []Group{{0, 5}, {5, 5}, {6, 11}, {11, 11}}},
|
|
|
|
|
{"ú.+ï", "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 22}}},
|
|
|
|
|
{"(?=hello)", "hello world", []Group{{0, 0}}},
|
|
|
|
|
{"(?!hello)", "hello world", []Group{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}}},
|
|
|
|
|
{"(?<=hello)", "hello world", []Group{{5, 5}}},
|
|
|
|
|
{"(?<!hello)", "hello world", []Group{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", "40", []Group{{0, 2}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", "040", []Group{}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", "400", []Group{{0, 3}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", "4000", []Group{}},
|
|
|
|
|
{"a{1,3}", "aaaaa", []Group{{0, 3}, {3, 5}}},
|
|
|
|
|
{`\\[ab\\]`, "a", []Group{}},
|
|
|
|
|
{`\\[ab\\]`, `\a`, []Group{{0, 2}}},
|
|
|
|
|
{"(abc|def|ghi)", nil, "abcdefg", []Group{{0, 3}, {3, 6}}},
|
|
|
|
|
{"a(b|c)d", nil, "abcd", []Group{}},
|
|
|
|
|
{"a(b|c)*d", nil, "abcbcd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)+d", nil, "abcbcd", []Group{{0, 6}}},
|
|
|
|
|
{"a(b|c)?d", nil, "abd", []Group{{0, 3}}},
|
|
|
|
|
{".+", nil, "hello world", []Group{{0, 11}}},
|
|
|
|
|
{"a.b", nil, "aXb", []Group{{0, 3}}},
|
|
|
|
|
{"a.*b", nil, "aXb", []Group{{0, 3}}},
|
|
|
|
|
{"a.{2,3}b", nil, "aXXb", []Group{{0, 4}}},
|
|
|
|
|
{"a.{2,}b", nil, "aXXXb", []Group{{0, 5}}},
|
|
|
|
|
{"a.{0,3}b", nil, "ab", []Group{{0, 2}}},
|
|
|
|
|
{"[abc]+", nil, "abcabc", []Group{{0, 6}}},
|
|
|
|
|
{"[a-zA-Z]+", nil, "HelloWorld", []Group{{0, 10}}},
|
|
|
|
|
{"[^abc]+", nil, "defghi", []Group{{0, 6}}},
|
|
|
|
|
{"^hello", nil, "hello world", []Group{{0, 5}}},
|
|
|
|
|
{"world$", nil, "hello world", []Group{{6, 11}}},
|
|
|
|
|
{`\bhello\b`, nil, "hello world", []Group{{0, 5}}},
|
|
|
|
|
{`\Bhello\B`, nil, "hello world", []Group{}},
|
|
|
|
|
{"(hello|world)", nil, "hello world", []Group{{0, 5}, {6, 11}}},
|
|
|
|
|
{"(hello|world)+", nil, "hello world", []Group{{0, 5}, {6, 11}}},
|
|
|
|
|
{"(hello|world)*", nil, "hello world", []Group{{0, 5}, {5, 5}, {6, 11}, {11, 11}}},
|
|
|
|
|
{"(hello|world)?", nil, "hello world", []Group{{0, 5}, {5, 5}, {6, 11}, {11, 11}}},
|
|
|
|
|
{"ú.+ï", nil, "úïäö´«åæïëòöê»éãçâï«úïòíñ", []Group{{0, 22}}},
|
|
|
|
|
{"(?=hello)", nil, "hello world", []Group{{0, 0}}},
|
|
|
|
|
{"(?!hello)", nil, "hello world", []Group{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}}},
|
|
|
|
|
{"(?<=hello)", nil, "hello world", []Group{{5, 5}}},
|
|
|
|
|
{"(?<!hello)", nil, "hello world", []Group{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", nil, "40", []Group{{0, 2}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", nil, "040", []Group{}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", nil, "400", []Group{{0, 3}}},
|
|
|
|
|
{"^((3[7-9])|([4-9][0-9])|([1-9][0-9][0-9])|(1000))$", nil, "4000", []Group{}},
|
|
|
|
|
{"a{1,3}", nil, "aaaaa", []Group{{0, 3}, {3, 5}}},
|
|
|
|
|
{`\\[ab\\]`, nil, "a", []Group{}},
|
|
|
|
|
{`\\[ab\\]`, nil, `\a`, []Group{{0, 2}}},
|
|
|
|
|
|
|
|
|
|
// Lookaround tests
|
|
|
|
|
{"(?<=bo)y", "boy", []Group{{2, 3}}},
|
|
|
|
|
{"bo(?=y)", "boy", []Group{{0, 2}}},
|
|
|
|
|
{"(?<=f)f+(?=f)", "fffff", []Group{{1, 4}}},
|
|
|
|
|
{"(?<=f)f+(?=f)", "fffffa", []Group{{1, 4}}},
|
|
|
|
|
{"(?<=bo)y", nil, "boy", []Group{{2, 3}}},
|
|
|
|
|
{"bo(?=y)", nil, "boy", []Group{{0, 2}}},
|
|
|
|
|
{"(?<=f)f+(?=f)", nil, "fffff", []Group{{1, 4}}},
|
|
|
|
|
{"(?<=f)f+(?=f)", nil, "fffffa", []Group{{1, 4}}},
|
|
|
|
|
|
|
|
|
|
// Test cases from Python's RE test suite
|
|
|
|
|
{`[\1]`, "\x01", []Group{{0, 1}}},
|
|
|
|
|
{`[\1]`, nil, "\x01", []Group{{0, 1}}},
|
|
|
|
|
|
|
|
|
|
{`\0`, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[\0a]`, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[\0a]`, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[a\0]`, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[^a\0]`, "\x00", []Group{}},
|
|
|
|
|
{`\0`, nil, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[\0a]`, nil, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[\0a]`, nil, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[a\0]`, nil, "\x00", []Group{{0, 1}}},
|
|
|
|
|
{`[^a\0]`, nil, "\x00", []Group{}},
|
|
|
|
|
|
|
|
|
|
{`\a[\b]\f\n\r\t\v`, "\a\b\f\n\r\t\v", []Group{{0, 7}}},
|
|
|
|
|
{`[\a][\b][\f][\n][\r][\t][\v]`, "\a\b\f\n\r\t\v", []Group{{0, 7}}},
|
|
|
|
|
{`\u`, "", nil},
|
|
|
|
|
{`\xff`, "ÿ", []Group{{0, 1}}},
|
|
|
|
|
{`\x00ffffffffffffff`, "\xff", []Group{}},
|
|
|
|
|
{`\x00f`, "\x0f", []Group{}},
|
|
|
|
|
{`\x00fe`, "\xfe", []Group{}},
|
|
|
|
|
{`^\w+=(\\[\000-\277]|[^\n\\])*`, "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c", []Group{{0, 32}}},
|
|
|
|
|
{`\a[\b]\f\n\r\t\v`, nil, "\a\b\f\n\r\t\v", []Group{{0, 7}}},
|
|
|
|
|
{`[\a][\b][\f][\n][\r][\t][\v]`, nil, "\a\b\f\n\r\t\v", []Group{{0, 7}}},
|
|
|
|
|
{`\u`, nil, "", nil},
|
|
|
|
|
{`\xff`, nil, "ÿ", []Group{{0, 1}}},
|
|
|
|
|
{`\x00ffffffffffffff`, nil, "\xff", []Group{}},
|
|
|
|
|
{`\x00f`, nil, "\x0f", []Group{}},
|
|
|
|
|
{`\x00fe`, nil, "\xfe", []Group{}},
|
|
|
|
|
{`^\w+=(\\[\000-\277]|[^\n\\])*`, nil, "SRC=eval.c g.c blah blah blah \\\\\n\tapes.c", []Group{{0, 32}}},
|
|
|
|
|
|
|
|
|
|
{`a.b`, nil, `acb`, []Group{{0, 3}}},
|
|
|
|
|
{`a.b`, nil, "a\nb", []Group{}},
|
|
|
|
|
{`a.*b`, nil, "acc\nccb", []Group{}},
|
|
|
|
|
{`a.{4,5}b`, nil, "acc\nccb", []Group{}},
|
|
|
|
|
{`a.b`, nil, "a\rb", []Group{{0, 3}}},
|
|
|
|
|
|
|
|
|
|
// Todo - add numeric range tests
|
|
|
|
|
}
|
|
|
|
@ -212,7 +219,7 @@ var groupTests = []struct {
|
|
|
|
|
func TestFindAllMatches(t *testing.T) {
|
|
|
|
|
for _, test := range reTests {
|
|
|
|
|
t.Run(test.re+" "+test.str, func(t *testing.T) {
|
|
|
|
|
regComp, err := Compile(test.re)
|
|
|
|
|
regComp, err := Compile(test.re, test.flags...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if test.result != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|