title: How to rewrite function from php to JS with a lot of regex
body: <p>I have a function in php which makes web friendly links. Now I want to write same function in JS, so I can make friendly url on fly. Here is function:</p>
  
  <pre><code>&lt;?php 
  function clearText($s)
  {
  
    $s = trim($s);
    $s = strtr($s, 'ĘÓĄŚŁŻŹŃęóąśłżźćń', 'EOASLZZCNeoaslzzcn');
    $s = preg_replace("/[^0-9a-zA-Z\s]/", "", $s);
    $s = preg_replace("/\s[\s]+/", " ", $s);
    $s = preg_replace("/\s/", "_", $s);
    $s = strtolower($s);
  
  
    return $s;
  }
  
  
  function imageReplace($s)
  {
    $s = clearText($s);
    $s = substr($s, 0, 64);
    return $s;
  }
  
  ?&gt;
  </code></pre>