std.regex replaceFirst vs. replaceFirstInto

Chris via Digitalmars-d digitalmars-d at
Thu May 21 04:51:51 PDT 2015

std.regex.replaceFirst uses

which returns the input, if no match is found. This is "safe", 
because the worst thing that can happen is that you get the input 
back unchanged.

std.regex.replaceFirstInto, on the other hand, uses

which may throw an exception like this:

phobos/std/regex/package.d(993): invalid submatch number 1*

Shouldn't this be reflected in the documentation? At the moment, 
the documentation of replaceFirstInto says:

"A variation on replaceFirst that instead of allocating a new 
string on each call outputs the result piece-wise to the sink."

But it doesn't mention the difference in behavior (i.e. return 
input vs. exception). In other words, with replaceFirstInto, you 
have to make sure that you can indeed replace.

The same probably goes for replaceAll / replaceAllInto.

*Exception stems from

More information about the Digitalmars-d mailing list