[英]Add carriage return using regex pattern of any number
我有这样的文字:
3 Q I think I started out, I said when4 you first noticed
the oyster beds, it sounded5 like it didn't really concern you, you did not6 believe that the dredging material or the berm7 building material could reach the oyster beds?8 A That's correct.9 Q
我需要有一个输出,该输出可以找到任何数字序列的第一个(即“ 10”不必是1和0的双精度匹配),并且看起来像这样(减去我必须在每行之间放置的空格) :
3 Q I think I started out, I said when
4 you first noticed the oyster beds, it sounded
5 like it didn't really concern you, you did not
6 believe that the dredging material or the berm
7 building material could reach the oyster beds?
8 A That's correct.
9 Q
我们可以尝试匹配模式:
(?<=.)(\d+)
这表示要匹配并捕获任意大小的数字,只要它不是文本中的第一个数字。 这样可以避免在以3
开头的第一行之前添加不必要的换行符。 然后,我们可以用换行符替换该捕获的数字。 这是一个工作脚本:
Dim regex As Regex = new Regex("(?<=.)(\d+)")
Console.WriteLine(regex.Replace("1 stuff10 more stuff", vbCrLf & "$1"))
输出:
1 stuff
10 more stuff
确保包含Imports Microsoft.VisualBasic
以便能够在您的代码中使用vbCrLf
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.