回答編集履歴
2
追記
answer
CHANGED
@@ -23,4 +23,6 @@
|
|
23
23
|
**実行結果** [Wandbox](https://wandbox.org/permlink/KEqLBZidcOWJYq5v)
|
24
24
|
```plain
|
25
25
|
10点一致しました({0}、{1}、{2}、{3}、{4}、{5}、{6}、{7}、{8}、{9})
|
26
|
-
```
|
26
|
+
```
|
27
|
+
|
28
|
+
[Matcher#replaceAll(Function<MatchResult,String>)](https://docs.oracle.com/javase/jp/10/docs/api/java/util/regex/Matcher.html#replaceAll(java.util.function.Function))
|
1
修正
answer
CHANGED
@@ -6,24 +6,21 @@
|
|
6
6
|
public static void main(String[] args) {
|
7
7
|
String src = "10点一致しました(%1、%2、%3、%4、%5、%6、%7、%8、%9、%10)";
|
8
8
|
|
9
|
-
|
9
|
+
String dst = Pattern.compile("%(\d+)")
|
10
10
|
.matcher(src)
|
11
|
+
.replaceAll(
|
12
|
+
m -> String.format(
|
13
|
+
"{%d}", Integer.valueOf(m.group(1)) - 1
|
14
|
+
)
|
15
|
+
)
|
11
16
|
;
|
12
|
-
|
13
|
-
String dst = matcher.replaceAll(
|
14
|
-
m -> {
|
15
|
-
return String.format(
|
16
|
-
"{%d}", Integer.valueOf(m.group(1)) - 1
|
17
|
-
);
|
18
|
-
}
|
19
|
-
);
|
20
17
|
|
21
18
|
System.out.println(dst);
|
22
19
|
}
|
23
20
|
}
|
24
21
|
```
|
25
22
|
|
26
|
-
**実行結果** [Wandbox](https://wandbox.org/permlink/
|
23
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/KEqLBZidcOWJYq5v)
|
27
24
|
```plain
|
28
25
|
10点一致しました({0}、{1}、{2}、{3}、{4}、{5}、{6}、{7}、{8}、{9})
|
29
26
|
```
|