s="foobarbaz" re=/[\s\S]/g newString="" while(current=re.exec(s)) {if(current.index<4||current.index>6) newString+=current[0]} alert(newString) // foobaz