Skip to content

Instantly share code, notes, and snippets.

@redspirit
Created January 9, 2014 11:20
Show Gist options
  • Save redspirit/8332675 to your computer and use it in GitHub Desktop.
Save redspirit/8332675 to your computer and use it in GitHub Desktop.
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
<h1>Антимат</h1>
var s = 'а бляха как';
//s = s.replace(/[?.,-]/gi, '');
//s = s.replace(/\s{2,}/gi, ' ');
var iskluch = [/бля(ха|шка)/i, /типа/i]
var r1 = new RegExp("[(\s|_)]*[бb6]+[(\s|_)]*[лl]+[(\s|_)]*([яy9])+[(\s|_)]*([дd]|[тt])*", "gi");
function zamena(str, a, b, c, d ,e, f){
var start = -1, end = -1;
var p1, p2;
var word;
var isMat = true;
var pos = b;
if(typeof(c) == 'number') pos = c;
if(typeof(d) == 'number') pos = d;
if(typeof(e) == 'number') pos = e;
if(typeof(f) == 'number') pos = f;
console.log(pos);
for(var n=1;n<s.length;n++){
p1 = pos-n;
p2 = pos+n;
if((s[p1] == ' ' || p1 <= 0) && start == -1) start = p1;
if((s[p2] == ' ' || p2 >= s.length) && end == -1) end = p2;
if(start >= 0 && end >= 0){
if (start > 1) start = start+1;
word = s.slice(start, end);
console.log(word);
break;
}
}
for(var i in iskluch){
if(iskluch[i].test(word)) {isMat = false; break; }
}
if(isMat)
return '***';
else
return str;
}
console.log(s.replace(r1, zamena));
{"view":"separate","fontsize":"100","seethrough":"","prefixfree":"1","page":"html"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment