Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用正则表达式对两个字符串执行Java AssertEquals_Regex_Junit - Fatal编程技术网

Regex 使用正则表达式对两个字符串执行Java AssertEquals

Regex 使用正则表达式对两个字符串执行Java AssertEquals,regex,junit,Regex,Junit,我有两条线: String actual = "abcd1234efgh"; String expected = "abcd5678efgh"; 数字部分总是不同的。 如何使assertEquals以最有效的方式将true返回给这些字符串?您可以使用: assertEquals(expected.replaceAll("\\D+", ""), actual.replaceAll("\\D+", "")); .replaceAll(“\\D+”,”)将从两个字符串对象中删除所有非数字。As

我有两条线:

String actual   = "abcd1234efgh";
String expected = "abcd5678efgh";
数字部分总是不同的。 如何使
assertEquals
以最有效的方式将
true
返回给这些字符串?

您可以使用:

assertEquals(expected.replaceAll("\\D+", ""), actual.replaceAll("\\D+", ""));

.replaceAll(“\\D+”,”)
将从两个字符串对象中删除所有非数字。

Assert.assertTrue(实际.matches(“abcdf\\D+efgh”))
实际=预期