Skip to content

regexp: \Q accepted without closing \E #76424

@matthias314

Description

@matthias314

Go version

go1.25 at https://go.dev/play/, also go1.22.2 linux/amd64

Output of go env in your module/workspace:

expand for output
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/matthias314/.cache/go-build'
GOENV='/home/matthias314/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/mnt/data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/mnt/data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.22/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build349479473=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I compiled a regexp containing \Q without the closing \E, for example `\Qabc`.

Example: https://go.dev/play/p/A-hbQUDBqsE

What did you see happen?

The regexp compiled and matches as if a final \E were present (`\Qabc\E`).

What did you expect to see?

An error during regexp compilation. As far as I understand the syntax, the final \E is required, not optional.

I do get an error if I enclose the regexp in brackets:

error parsing regexp: missing closing ): `(\Qabc)`

Enclosing a valid regexp in brackets should produce another valid regexp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions