回答編集履歴
2
追記
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
```Java
|
3
3
|
class Main {
|
4
4
|
public static void main( String[] args ){
|
5
|
-
String[] strs = {"abc", "ab", "acba"};
|
5
|
+
String[] strs = {"abc", "ab", "acba", "c"};
|
6
6
|
for(String str: strs) {
|
7
7
|
System.out.println(str.matches(".*[cb]"));
|
8
8
|
}
|
@@ -10,9 +10,30 @@
|
|
10
10
|
}
|
11
11
|
```
|
12
12
|
|
13
|
-
**実行結果** [Wandbox](https://wandbox.org/permlink/
|
13
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/eKfaPyWOborJJqIJ)
|
14
14
|
```
|
15
15
|
true
|
16
16
|
true
|
17
17
|
false
|
18
|
+
true
|
18
|
-
```
|
19
|
+
```
|
20
|
+
|
21
|
+
追記
|
22
|
+
---
|
23
|
+
@swordone さんからご指摘を受けて。前もってパターンをコンパイルする例。
|
24
|
+
```Java
|
25
|
+
import java.util.regex.Pattern;
|
26
|
+
|
27
|
+
class Main {
|
28
|
+
public static void main( String[] args ){
|
29
|
+
String[] strs = {"abc", "ab", "acba", "c"};
|
30
|
+
Pattern p = Pattern.compile(".*[cb]");
|
31
|
+
|
32
|
+
for(String str: strs) {
|
33
|
+
System.out.println(p.matcher(str).matches());
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
[Wandbox](https://wandbox.org/permlink/RxLWT4WWAangKis7)
|
1
修正
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
public static void main( String[] args ){
|
5
5
|
String[] strs = {"abc", "ab", "acba"};
|
6
6
|
for(String str: strs) {
|
7
|
-
System.out.println(str.matches(".
|
7
|
+
System.out.println(str.matches(".*[cb]"));
|
8
8
|
}
|
9
9
|
}
|
10
10
|
}
|