Q168504
by jun68ykt
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
JavaScript
const maskingWordsInSpeech =
(text) => text.replace(/[^a-z\[\(][a-z]+/ig, s => s.replace(/[a-z]/ig, '_'));
// 以下、テスト
[
'-[TOM] ♪ Taking care to keep my baggage with me ♪',
'-(banging) Huh?',
'- Are you hungry?',
'-[SNOOPY] I AM HunGry. (Sigh)'
].forEach(
text => console.log(maskingWordsInSpeech(text))
);