Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(s*)([0-9]+)s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(s*)([0-9]+)s*$", no.groups(1).value & no.groups(3).value)
Input string = "Introduction........................1"
出力文字列は "Introduction; 1"とする必要があります。
テキストの後のドットを無視する正規表現の変更方法を教えてください。
回答:
回答№1は1次のようにキャプチャグループを使用することができます:
Dim myMatch = Regex.Match("Introduction.............1", "(^.*?).*([0-9]+)s*$")
Dim res2 = myMatch.Groups(1).Value + ";" + myMatch.Groups(2).Value
ドットは .*
最終的な文字列の作成には使用されません。
編集:コードのコンテキストに合わせる:
Dim no as Match = Regex.Match("Introduction.............1", "(^.*?).*([0-9]+)s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(.*)([0-9]+)s*$", no.Groups(1).Value.Replace(".", "").Trim() & ";" & no.groups(2).value)
回答№2の場合は0
それは簡単な形式で、これはうまくいくはずです:
Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(.*)([0-9]+)s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(.*)([0-9]+)s*$", no.groups(1).value & ";" & no.groups(3).value)
正規表現はドットではなく空白でマッチしていました。
回答№3の場合は0
これはそうするでしょう:
wr_str = Regex.Replace(wr_str, "\.+", ";")
回答№4の場合は0
この正規表現パターンを試してみてください(ignorecase + multiline):
^(.*?).*?(d+)$
続きを見る - 正規表現テスター
http://i.imgur.com/qrTMsHr.png