仅从字符串中查找带点的数字

时间:2019-04-25 06:28:55

标签: c# regex

如何仅从字符串(例如,下面的字符串)中找到带点的数字

1. A traveller is thirsty in a desert at 15° E and 25° S. The desert in question is  (a) Kalahari (b) Patagonia (c) Sahara (d) Mohave 2. The Kalahari Desert, which stretches over 225,000 miles (900,000 sq. m), is in (a) Australia (b) (c) East Africa (d)

我想找到1.和2.并追加

在我尝试过

之前
string result = Regex.Replace(source, "\\d+", $"$0<br />");

,但它返回字符串中的所有数字。谢谢你。

1 个答案:

答案 0 :(得分:2)

在以上评论中,@ fubo

  

如何在点号为<br/>1.的数字前插入中断2.

var s = "1. A traveller is thirsty in a desert at 15° E [...] 2. The Kalahari Desert, [...]";

var result = Regex.Replace(s, "\\d+\\.", "<br/>$0");