小编nnt*_*nty的帖子

删除连续数字之间的空格

我有一个字符串,我想从中删除数字之间的空格:

string test = "Some Words 1 2 3 4";
string result = Regex.Replace(test, @"(\d)\s(\d)", @"$1$2");
Run Code Online (Sandbox Code Playgroud)

预期/期望的结果将是:

"Some Words 1234"
Run Code Online (Sandbox Code Playgroud)

但我检索以下内容:

"Some Words 12 34"
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

更多例子:

Input:  "Some Words That Should not be replaced 12 9 123 4 12"
Output: "Some Words That Should not be replaced 129123412"

Input:  "test 9 8"
Output: "test 98"

Input:  "t e s t 9 8"
Output: "t e s t 98"

Input:  "Another 12 000"
Output: "Another 12000"
Run Code Online (Sandbox Code Playgroud)

c# regex

32
推荐指数
2
解决办法
1781
查看次数

标签 统计

c# ×1

regex ×1