回答編集履歴
1
追記
answer
CHANGED
@@ -16,4 +16,26 @@
|
|
16
16
|
test/12345/67890/123
|
17
17
|
|
18
18
|
- 10文字以上続いた場合、2回マッチさせたいのか?
|
19
|
-
test/1234567890/123
|
19
|
+
test/1234567890/123
|
20
|
+
|
21
|
+
# 追記
|
22
|
+
とにかく4文字以下や6文字以上はNGで、2回でてくることはないという条件で
|
23
|
+
|
24
|
+
```
|
25
|
+
function check(str){
|
26
|
+
var def="00000";
|
27
|
+
var r=str.match(/(?:^|[^\d]+)(\d{5})(?:[^\d]+|$)/);
|
28
|
+
return r==null?def:r[1];
|
29
|
+
}
|
30
|
+
|
31
|
+
console.log(check("123")); //NG
|
32
|
+
console.log(check("12345")); //OK
|
33
|
+
console.log(check("test/1234567/56789/123/")); //OK
|
34
|
+
console.log(check("12345/123/123")); //OK
|
35
|
+
console.log(check("test/12345/123/")); //OK
|
36
|
+
console.log(check("test/1234/123/")); //NG
|
37
|
+
console.log(check("test/123456/123/")); //NG
|
38
|
+
console.log(check("test/123/12345")); // OK
|
39
|
+
console.log(check("test/123456/123")); // NG
|
40
|
+
console.log(check("test/1234567890/123")); // NG
|
41
|
+
```
|