Dotnet: .NET 4.7 Regex replace returns wrong string

Created on 3 Jul 2018  路  2Comments  路  Source: microsoft/dotnet

Dear Devs,
the following code is used:

'''
[TestClass]
public class DebugTests
{
[TestMethod]
public void OneSpaceStringTest()
{
var oneSpaceString = Regex.Replace("x x", "[ ]{2,}", " ");
Assert.AreEqual("x x", oneSpaceString);
}
}
'''

one would expect to get "x x" but returns in the FULL framework "xx" instead.
.NET Core returns the correct string.

Expectation is based on the test i did with RegexR

https://regexr.com/3rtdn

Martijn

Most helpful comment

How can folks repro this? I just ran Regex.Replace("x x", "[ ]{2,}", " ") on .NET Framework 4.7.2 and got "x x" as a result.

All 2 comments

How can folks repro this? I just ran Regex.Replace("x x", "[ ]{2,}", " ") on .NET Framework 4.7.2 and got "x x" as a result.

The server was running 4.7.1 and not 4.7.2
@jnm2 4.7.2 runs like a sharm. Thanks

Was this page helpful?
0 / 5 - 0 ratings