回答編集履歴
2
追記
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
public static void main( String[] args ){
|
8
8
|
|
9
|
-
String[] strs = {"abc", "ab", "acba"};
|
9
|
+
String[] strs = {"abc", "ab", "acba", "c"};
|
10
10
|
|
11
11
|
for(String str: strs) {
|
12
12
|
|
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
**実行結果** [Wandbox](https://wandbox.org/permlink/
|
25
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/eKfaPyWOborJJqIJ)
|
26
26
|
|
27
27
|
```
|
28
28
|
|
@@ -32,4 +32,46 @@
|
|
32
32
|
|
33
33
|
false
|
34
34
|
|
35
|
+
true
|
36
|
+
|
35
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
追記
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
@swordone さんからご指摘を受けて。前もってパターンをコンパイルする例。
|
46
|
+
|
47
|
+
```Java
|
48
|
+
|
49
|
+
import java.util.regex.Pattern;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
class Main {
|
54
|
+
|
55
|
+
public static void main( String[] args ){
|
56
|
+
|
57
|
+
String[] strs = {"abc", "ab", "acba", "c"};
|
58
|
+
|
59
|
+
Pattern p = Pattern.compile(".*[cb]");
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
for(String str: strs) {
|
64
|
+
|
65
|
+
System.out.println(p.matcher(str).matches());
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
[Wandbox](https://wandbox.org/permlink/RxLWT4WWAangKis7)
|
1
修正
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
for(String str: strs) {
|
12
12
|
|
13
|
-
System.out.println(str.matches(".
|
13
|
+
System.out.println(str.matches(".*[cb]"));
|
14
14
|
|
15
15
|
}
|
16
16
|
|