回答編集履歴
2
変数名を修正
test
CHANGED
@@ -14,11 +14,13 @@
|
|
14
14
|
|
15
15
|
```JavaScript
|
16
16
|
|
17
|
+
'use strict';
|
18
|
+
|
17
19
|
const string = '-[TOM] ♪ Taking care to keep my baggage with me ♪\n-(banging) Huh?';
|
18
20
|
|
19
|
-
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match, alphabet
|
21
|
+
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match, alphabet) {
|
20
22
|
|
21
|
-
return alphabet
|
23
|
+
return alphabet ? '_' : match;
|
22
24
|
|
23
25
|
});
|
24
26
|
|
1
[] の処理を追加
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
const string = '-[TOM] ♪ Taking care to keep my baggage with me ♪\n-(banging) Huh?';
|
18
18
|
|
19
|
-
const result = string.replace(/([^)]*)|([a-zA-Z])/g, function callbackfn (match, alphabetString) {
|
19
|
+
const result = string.replace(/([^)]*)|[[^]]*]|([a-zA-Z])/g, function callbackfn (match, alphabetString) {
|
20
20
|
|
21
21
|
return alphabetString ? '_' : match;
|
22
22
|
|
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
console.log(result); // "-[
|
27
|
+
console.log(result); // "-[TOM] ♪ ______ ____ __ ____ __ _______ ____ __ ♪\n-(banging) ___?"
|
28
28
|
|
29
29
|
```
|
30
30
|
|