Compare commits
3 Commits
304ef68d45
...
68a3581d93
Author | SHA1 | Date | |
---|---|---|---|
68a3581d93 | |||
ff250338b4 | |||
0367c0d614 |
7
noteOnPCREBackreferences.txt
Normal file
7
noteOnPCREBackreferences.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
In PCRE, following a backreference by _any_ number seems to turn it into an octal value. Why is this?
|
||||
|
||||
Eg.
|
||||
`(a)\1` <-- Backreference
|
||||
`(a)\17` <-- Octal '17'
|
||||
`(a)\19` <-- Octal 1, then literal 9
|
||||
`(a)\1a` <-- Backreference, then 'a'
|
43
re_test.go
43
re_test.go
@@ -280,6 +280,18 @@ var reTests = []struct {
|
||||
{`ab*`, nil, `xabyabbbz`, []Group{{1, 3}, {4, 8}}},
|
||||
{`ab*`, nil, `xayabbbz`, []Group{{1, 2}, {3, 7}}},
|
||||
{`[abhgefdc]ij`, nil, `hij`, []Group{{0, 3}}},
|
||||
{`a[bcd]*dcdcde`, nil, `adcdcde`, []Group{{0, 7}}},
|
||||
{`a[bcd]+dcdcde`, nil, `adcdcde`, []Group{}},
|
||||
{`[a-zA-Z_][a-zA-Z0-9_]*`, nil, `alpha`, []Group{{0, 5}}},
|
||||
{`multiple words of text`, nil, `uh-uh`, []Group{}},
|
||||
{`multiple words`, nil, `multiple words, yeah`, []Group{{0, 14}}},
|
||||
{`[k]`, nil, `ab`, []Group{}},
|
||||
{`a[-]?c`, nil, `ac`, []Group{{0, 2}}},
|
||||
{`^(.+)?B`, nil, `AB`, []Group{{0, 2}}},
|
||||
|
||||
// At this point, the python test suite has a bunch
|
||||
// of backreference tests. Since my engine doesn't
|
||||
// implement backreferences, I've skipped those tests.
|
||||
|
||||
// Todo - add numeric range tests
|
||||
}
|
||||
@@ -326,6 +338,37 @@ var groupTests = []struct {
|
||||
{`(abc|)ef`, nil, `abcdef`, []Match{[]Group{{4, 6}, {4, 4}}}},
|
||||
{`(a|b)c*d`, nil, `abcd`, []Match{[]Group{{1, 4}, {1, 2}}}},
|
||||
{`(ab|ab*)bc`, nil, `abc`, []Match{[]Group{{0, 3}, {0, 1}}}},
|
||||
{`a([bc]*)c*`, nil, `abc`, []Match{[]Group{{0, 3}, {1, 3}}}},
|
||||
{`a([bc]*)(c*d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 3}, {3, 4}}}},
|
||||
{`a([bc]+)(c*d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 3}, {3, 4}}}},
|
||||
{`a([bc]*)(c+d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {1, 2}, {2, 4}}}},
|
||||
{`(ab|a)b*c`, nil, `abc`, []Match{[]Group{{0, 3}, {0, 2}}}},
|
||||
{`((a)(b)c)(d)`, nil, `abcd`, []Match{[]Group{{0, 4}, {0, 3}, {0, 1}, {1, 2}, {3, 4}}}},
|
||||
{`^a(bc+|b[eh])g|.h$`, nil, `abh`, []Match{[]Group{{1, 3}}}},
|
||||
{`(bc+d$|ef*g.|h?i(j|k))`, nil, `effgz`, []Match{[]Group{{0, 5}, {0, 5}}}},
|
||||
{`(bc+d$|ef*g.|h?i(j|k))`, nil, `ij`, []Match{[]Group{{0, 2}, {0, 2}, {1, 2}}}},
|
||||
{`(bc+d$|ef*g.|h?i(j|k))`, nil, `effg`, []Match{}},
|
||||
{`(bc+d$|ef*g.|h?i(j|k))`, nil, `bcdd`, []Match{}},
|
||||
{`(bc+d$|ef*g.|h?i(j|k))`, nil, `reffgz`, []Match{[]Group{{1, 6}, {1, 6}}}},
|
||||
{`(((((((((a)))))))))`, nil, `a`, []Match{[]Group{{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}}},
|
||||
{`(.*)c(.*)`, nil, `abcde`, []Match{[]Group{{0, 5}, {0, 2}, {3, 5}}}},
|
||||
{`\((.*), (.*)\)`, nil, `(a, b)`, []Match{[]Group{{0, 6}, {1, 2}, {4, 5}}}},
|
||||
|
||||
// At this point, the python test suite has a bunch
|
||||
// of backreference tests. Since my engine doesn't
|
||||
// implement backreferences, I've skipped those tests.
|
||||
|
||||
{`(a)(b)c|ab`, nil, `ab`, []Match{[]Group{{0, 2}}}},
|
||||
{`(a)+x`, nil, `aaax`, []Match{[]Group{{0, 4}, {2, 3}}}},
|
||||
{`([ac])+x`, nil, `aacx`, []Match{[]Group{{0, 4}, {2, 3}}}},
|
||||
{`([^/]*/)*sub1/`, nil, `d:msgs/tdir/sub1/trial/away.cpp`, []Match{[]Group{{0, 17}, {7, 12}}}},
|
||||
{`([^.]*)\.([^:]*):[T ]+(.*)`, nil, `track1.title:TBlah blah blah`, []Match{[]Group{{0, 28}, {0, 6}, {7, 12}, {14, 28}}}},
|
||||
{`([^N]*N)+`, nil, `abNNxyzN`, []Match{[]Group{{0, 8}, {4, 8}}}},
|
||||
{`([^N]*N)+`, nil, `abNNxyz`, []Match{[]Group{{0, 4}, {3, 4}}}},
|
||||
{`([abc]*)x`, nil, `abcx`, []Match{[]Group{{0, 4}, {0, 3}}}},
|
||||
{`([abc]*)x`, nil, `abc`, []Match{}},
|
||||
{`([xyz]*)x`, nil, `abcx`, []Match{[]Group{{3, 4}, {3, 3}}}},
|
||||
{`(a)+b|aac`, nil, `aac`, []Match{[]Group{{0, 3}}}},
|
||||
}
|
||||
|
||||
func TestFindAllMatches(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user