回答編集履歴

1

回答の修正

2020/01/22 03:39

投稿

yureighost
yureighost

スコア2183

test CHANGED
@@ -11,3 +11,29 @@
11
11
  var result = matche.Value;
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ 前の回答だとghiも含まれてしまうので少し手直ししてみました。
18
+
19
+ $~$のパターンが二つ以上あるが、パターン内の文字をmatchさせたくないなら、
20
+
21
+ 正規表現の$の間の.(任意の一文字)を[^$]($以外)にしてmatchした文字を全て結合させればいけると思います。
22
+
23
+ ```C#
24
+
25
+ using System.Linq;
26
+
27
+ using System.Text.RegularExpressions;
28
+
29
+ ・・・
30
+
31
+ string srcStr = "abc$def$ghi$jkl$mno";
32
+
33
+ string ptn = @"($[^$]*$)";
34
+
35
+ MatchCollection matches = Regex.Matches(srcStr, ptn);
36
+
37
+ string result = String.Join("", matches.Cast<Match>());
38
+
39
+ ```