teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

修正

2017/04/18 06:39

投稿

think49
think49

スコア18194

answer CHANGED
@@ -5,15 +5,15 @@
5
5
 
6
6
  if (brackets) {
7
7
  for (var i = 0, len = brackets.length; i < len; ++i) {
8
- brackets[i] = brackets[i].slice(1, -1);
8
+ brackets[i] = brackets[i].slice(1, -1).match(/-|[^-]+/g);
9
9
  }
10
10
  }
11
11
 
12
12
  return brackets;
13
13
  }
14
14
 
15
- console.log(JSON.stringify(sample('テスト1{=test1-string1.test2-string2}-終わり'))); // ["=test1-string1.test2-string2"]
15
+ console.log(JSON.stringify(sample('テスト1{=test1-string1.test2-string2}-終わり'))); // [["=test1","-","string1.test2","-","string2"]]
16
- console.log(JSON.stringify(sample('-{test1-string1}-{test2}-{test3-foo3-piyo3}'))); // ["test1-string1","test3-foo3-piyo3"]
16
+ console.log(JSON.stringify(sample('-{test1-string1}-{test2}-{test3-foo3-piyo3}'))); // [["test1","-","string1"],["test3","-","foo3","-","piyo3"]]
17
17
  ```
18
18
 
19
19
  Re: litteone さん