回答編集履歴

1

追記

2017/10/27 02:14

投稿

yambejp
yambejp

スコア114814

test CHANGED
@@ -35,3 +35,47 @@
35
35
  - 10文字以上続いた場合、2回マッチさせたいのか?
36
36
 
37
37
  test/1234567890/123
38
+
39
+
40
+
41
+ # 追記
42
+
43
+ とにかく4文字以下や6文字以上はNGで、2回でてくることはないという条件で
44
+
45
+
46
+
47
+ ```
48
+
49
+ function check(str){
50
+
51
+ var def="00000";
52
+
53
+ var r=str.match(/(?:^|[^\d]+)(\d{5})(?:[^\d]+|$)/);
54
+
55
+ return r==null?def:r[1];
56
+
57
+ }
58
+
59
+
60
+
61
+ console.log(check("123")); //NG
62
+
63
+ console.log(check("12345")); //OK
64
+
65
+ console.log(check("test/1234567/56789/123/")); //OK
66
+
67
+ console.log(check("12345/123/123")); //OK
68
+
69
+ console.log(check("test/12345/123/")); //OK
70
+
71
+ console.log(check("test/1234/123/")); //NG
72
+
73
+ console.log(check("test/123456/123/")); //NG
74
+
75
+ console.log(check("test/123/12345")); // OK
76
+
77
+ console.log(check("test/123456/123")); // NG
78
+
79
+ console.log(check("test/1234567890/123")); // NG
80
+
81
+ ```