mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
regexp: allow escaping of any punctuation
More in line with other regexp packages and egrep; accommodates overzealous escapers. R=r CC=golang-dev https://golang.org/cl/1008041
This commit is contained in:
parent
43409ed2c6
commit
6f33f34bbc
2 changed files with 13 additions and 4 deletions
|
|
@ -28,6 +28,7 @@ var good_re = []string{
|
|||
`[abc]`,
|
||||
`[^1234]`,
|
||||
`[^\n]`,
|
||||
`\!\\`,
|
||||
}
|
||||
|
||||
type stringError struct {
|
||||
|
|
@ -100,6 +101,14 @@ var matches = []tester{
|
|||
// fixed bugs
|
||||
tester{`ab$`, "cab", vec{1, 3}},
|
||||
tester{`axxb$`, "axxcb", vec{}},
|
||||
|
||||
// can backslash-escape any punctuation
|
||||
tester{`\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~`,
|
||||
`!"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, vec{0, 31}},
|
||||
tester{`[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\{\|\}\~]+`,
|
||||
`!"#$%&'()*+,-./:;<=>?@[\]^_{|}~`, vec{0, 31}},
|
||||
tester{"\\`", "`", vec{0, 1}},
|
||||
tester{"[\\`]+", "`", vec{0, 1}},
|
||||
}
|
||||
|
||||
func compileTest(t *testing.T, expr string, error os.Error) *Regexp {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue