Skip to content

bugs for regexp.ReplaceAllString? #69475

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

Closed
wuceyang opened this issue Sep 15, 2024 · 2 comments
Closed

bugs for regexp.ReplaceAllString? #69475

wuceyang opened this issue Sep 15, 2024 · 2 comments

Comments

@wuceyang
Copy link

wuceyang commented Sep 15, 2024

Go version

1.22.2

Output of go env in your module/workspace:

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env  
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Administrator\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Administrator\go
set GOPRIVATE=
set GOPROXY=http://172.16.130.132:8081/repository/go-local/
set GOROOT=D:/Program Files/Go1.22.2
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\Work\Git\system-watcher-api\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build2208406462=/tmp/go-build -gno-record-gcc-switches

What did you do?

when i rename uploaded filenames, codes below

package main
import (
    "fmt"
    "regexp"
)
func main () {
    var filename = "abc.123.txt"
    var pattern = regexp.MustCompile("^(.+?)\\.([^\\.]+)$")
    fmt.Println(pattern.ReplaceAllString(filename, "$1_.$2"))
}

What did you see happen?

output result: .txt

image
even when the codes like this

fmt.Println(pattern.ReplaceAllString(filename, "$1000.$2"))

the result unchanged

What did you expect to see?

it seems that golang can't get group no and strings
when i try this replacement in javascript and c#, the out is "abc.123000.txt", which is my expected result
image
image

@seankhliao
Copy link
Member

https://go.dev/play/p/hIgPEsAiel1

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 Sep 15, 2024
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

3 participants