D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7674 - regex replace requires escaped format
Summary: regex replace requires escaped format
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-08 14:10 UTC by Jesse Phillips
Modified: 2012-03-22 14:02 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jesse Phillips 2012-03-08 14:10:44 UTC
When using std.regex.replace the format parameter is also requiring to be a valid regex. The below example is expected to pass

import std.regex;

void main() {
	auto str = "hello?";

	assert(str.replace(regex(r"\?", "g"), r"\?") == r"hello\?");
}

This should fail:

import std.regex;

void main() {
	auto str = "hello?";

	assert(str.replace(regex(r"\?", "g"), r"\\?") != r"hello\?");
}

Maybe I'm wrong on this, but the current requirement seems off.
Comment 1 Dmitry Olshansky 2012-03-09 03:30:45 UTC
(In reply to comment #0)
> When using std.regex.replace the format parameter is also requiring to be a
> valid regex.
Strange.
But speaking of format string it is expected to be a plain string there is no need to escape a thing in there IRC.

 The below example is expected to pass
> 
> import std.regex;
> 
> void main() {
>     auto str = "hello?";
> 
>     assert(str.replace(regex(r"\?", "g"), r"\?") == r"hello\?");
> }
> 
> This should fail:
> 
> import std.regex;
> 
> void main() {
>     auto str = "hello?";
> 
>     assert(str.replace(regex(r"\?", "g"), r"\\?") != r"hello\?");
> }
> 
> Maybe I'm wrong on this, but the current requirement seems off.
Apparently it is, I'll take a look.
Comment 2 github-bugzilla 2012-03-17 11:04:23 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/097faaca84b0d8f4031cc56721ec846ff4bd6a6e
fix Issue 7674 - regex replace requires escaped format

Kill unnecessary escaping in replace format string.

https://github.com/D-Programming-Language/phobos/commit/bdaa3260ffe62237d7360e84f8e6f01b30e4ab54
changelog entry for issue 7674

https://github.com/D-Programming-Language/phobos/commit/55debbccd020059aec0764cbcbd1773c3a85fe73
Merge pull request #492 from blackwhale/issue-7674

Issue 7674 - regex replace requires escaped format