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

Add support backslash reference in Replace() #9

Closed
vkd opened this issue Mar 23, 2017 · 2 comments
Closed

Add support backslash reference in Replace() #9

vkd opened this issue Mar 23, 2017 · 2 comments

Comments

@vkd
Copy link

vkd commented Mar 23, 2017

Test case:

func TestReplaceRef(t *testing.T) {
	re := MustCompile("(123)hello(789)", None)
	res, err := re.Replace("123hello789", "\\1456\\2", -1, -1)
	if err != nil {
		t.Fatal(err)
	}
	if res != "123456789" {
		t.Fatalf("Wrong result: %s", res)
	}
}

Result:

--- FAIL: TestReplaceRef (0.00s)
	regexp_test.go:775: Wrong result: \1456\2
@dlclark
Copy link
Owner

dlclark commented Mar 23, 2017

Which languages regex spec are you wanting this to be modeled after?

There are lots of features related to the $ replace syntax (https://msdn.microsoft.com/en-us/library/ewy2t5e0(v=vs.110).aspx) so the implementation is a bit more involved than just allowing \ or $ to start reference groups in replace strings.

@vkd
Copy link
Author

vkd commented Mar 23, 2017

Sorry, I confused and forgot that this package based on .NET regexp engine.

This issue may be closed.

@dlclark dlclark closed this as completed Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants