回答編集履歴
2
変数名を修正
answer
CHANGED
@@ -6,9 +6,10 @@
|
|
6
6
|
括弧全体にマッチさせてから、マッチした文字列をそのまま返す置換処理にしてください。
|
7
7
|
|
8
8
|
```JavaScript
|
9
|
+
'use strict';
|
9
10
|
const string = '-[TOM] ♪ Taking care to keep my baggage with me ♪\n-(banging) Huh?';
|
10
|
-
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match,
|
11
|
+
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match, alphabet) {
|
11
|
-
return
|
12
|
+
return alphabet ? '_' : match;
|
12
13
|
});
|
13
14
|
|
14
15
|
console.log(result); // "-[TOM] ♪ ______ ____ __ ____ __ _______ ____ __ ♪\n-(banging) ___?"
|
1
[] の処理を追加
answer
CHANGED
@@ -7,11 +7,11 @@
|
|
7
7
|
|
8
8
|
```JavaScript
|
9
9
|
const string = '-[TOM] ♪ Taking care to keep my baggage with me ♪\n-(banging) Huh?';
|
10
|
-
const result = string.replace(/([^)]*)|([a-zA-Z])/g, function callbackfn (match, alphabetString) {
|
10
|
+
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match, alphabetString) {
|
11
11
|
return alphabetString ? '_' : match;
|
12
12
|
});
|
13
13
|
|
14
|
-
console.log(result); // "-[
|
14
|
+
console.log(result); // "-[TOM] ♪ ______ ____ __ ____ __ _______ ____ __ ♪\n-(banging) ___?"
|
15
15
|
```
|
16
16
|
|
17
17
|
### 丸投げ質問
|