diff --git a/regexp_test.go b/regexp_test.go index ceb43bb..5dd3853 100644 --- a/regexp_test.go +++ b/regexp_test.go @@ -777,6 +777,21 @@ func TestECMAInvalidEscapeCharClass(t *testing.T) { } } +func TestECMAScriptXCurlyBraceEscape(t *testing.T) { + re := MustCompile(`\x{20}`, ECMAScript) + if m, err := re.MatchString(" "); err != nil { + t.Fatal(err) + } else if m { + t.Fatal("Expected no match") + } + + if m, err := re.MatchString("xxxxxxxxxxxxxxxxxxxx"); err != nil { + t.Fatal(err) + } else if !m { + t.Fatal("Expected match") + } +} + func TestNegateRange(t *testing.T) { re := MustCompile(`[\D]`, 0) if m, err := re.MatchString("A"); err != nil { diff --git a/syntax/parser.go b/syntax/parser.go index c3088d0..a991cfc 100644 --- a/syntax/parser.go +++ b/syntax/parser.go @@ -1663,8 +1663,11 @@ func (p *parser) scanCharEscape() (r rune, err error) { case 'x': // support for \x{HEX} syntax from Perl and PCRE if p.charsRight() > 0 && p.rightChar(0) == '{' { + if p.useOptionE() { + return ch, nil + } p.moveRight(1) - r, err = p.scanHexUntilBrace() + return p.scanHexUntilBrace() } else { r, err = p.scanHex(2) }