[英]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.