Skip to content

Instantly share code, notes, and snippets.

@tarunon
Last active August 29, 2015 13:56
Show Gist options
  • Save tarunon/8936778 to your computer and use it in GitHub Desktop.
Save tarunon/8936778 to your computer and use it in GitHub Desktop.
短文の末尾に(某)を付けるためのスクリプト。
var mScript = function(text) {
// 正規表現パターンで付加する文字を決定する。
var regs = {
"命令懇願": /[えけげせぜてでねへべぺめれ]よ?[。.]?$/,
"疑問惑困": /[??]$/,
"嬉輝喜怒哀楽": /[!!]$/,
"困惑": /[えけげせぜてでねへべぺめれ][んぬ][。.]?$/,
"飛旅": /旅行/,
"期待輝余裕勃": /.*/
};
// 正規表現に一致したらkeyからランダムに1文字追加。
for (var key in regs) {
if(text.match(regs[key])) {
text += '(' + key.charAt(key.length * Math.random()) + ')';
break;
}
}
return text;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment