回答編集履歴
1
chousei
test
CHANGED
@@ -39,3 +39,49 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
# 調整版
|
46
|
+
|
47
|
+
あ、2番めはマッチするですね、であればこうです
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
|
51
|
+
function regexTest(str){
|
52
|
+
|
53
|
+
const pattern=".*?[0-5]?[0-9]:[0-5]?[0-9] ?.*?";
|
54
|
+
|
55
|
+
const r1 = RegExp('^(?:'+pattern+' ?)+$');
|
56
|
+
|
57
|
+
const r2 = RegExp(pattern+'( |$)','g');
|
58
|
+
|
59
|
+
if(r1.test(str)){
|
60
|
+
|
61
|
+
const r3=str.match(r2);
|
62
|
+
|
63
|
+
console.log('match')
|
64
|
+
|
65
|
+
return r3;
|
66
|
+
|
67
|
+
} else {
|
68
|
+
|
69
|
+
console.log('unmatch')
|
70
|
+
|
71
|
+
return undefined
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
console.log(regexTest('hoge hoge'));
|
78
|
+
|
79
|
+
console.log(regexTest('0:18 hoge'));
|
80
|
+
|
81
|
+
console.log(regexTest('hoge 0:34 hoge'));
|
82
|
+
|
83
|
+
console.log(regexTest('0:18 hoge 0:34 hoge'));
|
84
|
+
|
85
|
+
console.log(regexTest('0:18 hoge 0:34 hoge 0:41 hoge 0:55 hoge'));
|
86
|
+
|
87
|
+
```
|