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

回答編集履歴

3

些細な修正

2021/10/05 00:49

投稿

itagagaki
itagagaki

スコア8402

answer CHANGED
@@ -5,4 +5,4 @@
5
5
  console.log( (text.match( ///g ) || []).length + 10 * (text.match( /#/g ) || []).length );
6
6
  ```
7
7
 
8
- 置き換えた結果の文字列必要なら`/`と`#`について別途2回replaceすればよろしいかと。
8
+ 置き換えた結果の文字列必要なら、上記のカウントとは別に、すでに質問で試されているように、`/`と`#`について2回replaceすればよろしいかと。

2

追記

2021/10/05 00:49

投稿

itagagaki
itagagaki

スコア8402

answer CHANGED
@@ -1,6 +1,8 @@
1
- もし置き換えた結果の文字列が必要ないなら
1
+ もし置き換えた結果の文字列が必要なくカウントだけできればよなら
2
2
 
3
3
  ```JavaScript
4
4
  const text = 'hello#world/good#morning';
5
5
  console.log( (text.match( ///g ) || []).length + 10 * (text.match( /#/g ) || []).length );
6
- ```
6
+ ```
7
+
8
+ 置き換えた結果の文字列が必要なら`/`と`#`について別途2回replaceすればよろしいかと。

1

注釈

2021/10/05 00:47

投稿

itagagaki
itagagaki

スコア8402

answer CHANGED
@@ -1,3 +1,5 @@
1
+ もし置き換えた結果の文字列が必要ないなら
2
+
1
3
  ```JavaScript
2
4
  const text = 'hello#world/good#morning';
3
5
  console.log( (text.match( ///g ) || []).length + 10 * (text.match( /#/g ) || []).length );