Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: wrong match #68281

Closed
ethanvc opened this issue Jul 3, 2024 · 4 comments
Closed

regexp: wrong match #68281

ethanvc opened this issue Jul 3, 2024 · 4 comments

Comments

@ethanvc
Copy link

ethanvc commented Jul 3, 2024

Go version

go 1.22.0

Output of go env in your module/workspace:

$ go env
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/Library/Caches/go-build'
GOENV='/Users/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/.gvm/pkgsets/go1.22.4/global/pkg/mod'
GOOS='darwin'
GOPATH='/Users/.gvm/pkgsets/go1.22.4/global'
GOPROXY='https://proxy.golang.org,https://goproxy.io,direct'
GOROOT='/Users/go/go1.22.0'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/go/go1.22.0/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/qz/53hk_dj559zgbmkxl19vmwtm0000gp/T/go-build1960665975=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?


package main

import (
	"fmt"
	"regexp"
)

func main() {
	x, err := regexp.MatchString(`^7|$`, "800000")
	fmt.Println(x, err)
}

What did you see happen?

true

What did you expect to see?

false, do not match.

@Shion1305
Copy link

Shion1305 commented Jul 3, 2024

Hello, @ethanvc!

Do you recognize that regexp.MatchString takes the first argument as a pattern and the second argument as a target string?
7| means 7 or nothing in regex, so this is correct behavior.
You can check from here
Screenshot 2024-07-03 at 15 59 29

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
@ethanvc
Copy link
Author

ethanvc commented Jul 3, 2024

Hello, @ethanvc!

Do you recognize that regexp.MatchString takes the first argument as a pattern and the second argument as a target string? 7| means 7 or nothing in regex, so this is correct behavior. You can check from here Screenshot 2024-07-03 at 15 59 29

thanks, understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants