Skip to content

Conversation

@krystiannowak
Copy link

@krystiannowak krystiannowak commented Jan 13, 2026

Currently when trying to use string replacement like in:
https://regex101.com/r/UFsDMr/1
so having regular expression:

^(BRAVO-(GOLF)|(ALPHA|BRAVO|CHARLIE|DELTA|ECHO|FOXTROT)).*

and test string:

BRAVO-CHARLIE something

and replacement:

${2}${3}

the following runtime error is thrown:

panic: runtime error: unsafe.Slice: ptr is nil and len is not zero [recovered, repanicked]

goroutine 11 [running]:
testing.tRunner.func1.2({0x104462a20, 0x104492aa0})
	/opt/homebrew/opt/go/libexec/src/testing/testing.go:1872 +0x190
testing.tRunner.func1()
	/opt/homebrew/opt/go/libexec/src/testing/testing.go:1875 +0x31c
panic({0x104462a20?, 0x104492aa0?})
	/opt/homebrew/opt/go/libexec/src/runtime/panic.go:783 +0x120
go.elara.ws/pcre.ConvertGlob({0x1043f40b3, 0x7})
	/somemydir/pcre/glob.go:56 +0x1f0
go.elara.ws/pcre.CompileGlob({0x1043f40b3?, 0x11e1add08?})
	/somemydir/pcre/glob.go:66 +0x20
go.elara.ws/pcre_test.TestCompileGlob(0x14000186a80)

as capture group not participating in the match are still tried to be accessed, but they should be allowed and if their value is not set should not produce any replacement value (= they should be an empty string).

This PR fixes that incorrect behaviour, so that the above regular expression replacement results in expected:

BRAVO

string.

@krystiannowak
Copy link
Author

Raised also https://gitea.elara.ws/Elara6331/pcre/issues/7 for that

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

Successfully merging this pull request may close these issues.

1 participant