|
|
|
| Всем привет! Очень нужен фильтр слов.
Вот нашел один но он очень длинный может можно его как-то в одну строку записать?
<script>
function repla(sText)
{
var mywords = /((х|x)(у|y)(й|е|ё|и|я|ли\W|э))/gi;
return repls(sText.replace(mywords, "*МАТ?*"));
}
function repls(sText)
{
var mywords = /(п(и|е|ё)(з|с)д)/i;
return repld(sText.replace(mywords, "*МАТ?*"));
}
function repld(sText)
{
var mywords = /(\Wу?би?л(я\W|яд|ят|юдо?к))/gi;
return replf(sText.replace(mywords, "*МАТ?*"));
}
function replf(sText)
{
var mywords = /(пид(о|а)р|п(е|и)дри)/gi;
return replg(sText.replace(mywords, "*МАТ?*"));
}
function replg(sText)
{
var mywords = /(муд(ак|о|и))/gi;
return replh(sText.replace(mywords, "*МАТ?*"));
}
function replh(sText)
{
var mywords = /((\W|по|на)(х|x)(е|e)(р|p))/gi;
return replj(sText.replace(mywords, "*МАТ?*"));
}
function replj(sText)
{
var mywords = /(з(а|о)луп(а|и))/gi;
return replk(sText.replace(mywords, "*МАТ?*"));
}
function replk(sText)
{
var mywords = /((\W|о|д|а|ь|ъ)(е|ё|и)б(а|ы|уч|усь|нут|ись))/gi
return repll(sText.replace(mywords, "*МАТ?*"));
}
function repll(sText)
{
var mywords = /(\W(на|по)х\W)/gi;
return sText.replace(mywords, "*МАТ?*");
}
</script>
|
| |
|
|
|
|
автор: 0987654 (30.06.2011 в 17:43) |
|
|
для: see
(30.06.2011 в 17:11)
| | Можно.
Не в "одну", конечно, но подсократить можно существенно.
Делаем всего ОДНУ функцию, в которой будет массив "ругательных" слов и затем цикл, который этот массив переберёт. Для примера использовал два слова - первое и последнее:
function antimat (sText)
{
var words = new Array ('(х|x)(у|y)(й|е|ё|и|я|ли\W|э)', '\W(на|по)х\W');
for (var j = 0; j < words.length; j++) sText = sText.replace (new RegExp (words [j], 'gi'), '*MAT?*');
return sText;
}
|
| |
|
|
|