title: Scala expression to replace a file extension in a string
body: <p>Here is a version I wrote using split:</p>
  
  <pre><code>fileName.split('.').init ++ Seq("js") mkString "."
  </code></pre>
  
  <p>This transforms e.g. <code>foo.bar.coffee</code> into <code>foo.bar.js</code>.</p>
  
  <p>What I like:</p>
  
  <ul>
  <li>it works</li>
  <li>it doesn't rely on things like <code>indexOf()</code></li>
  <li>it feels functional ;)</li>
  </ul>
  
  <p>What I don't like:</p>
  
  <ul>
  <li>it's not as short as I would hope</li>
  <li>it might confuse some readers</li>
  </ul>
  
  <p>How can I write an even simpler / straightforward version?</p>
  
  <p><strong>UPDATE: Great answers below! In short:</strong></p>
  
  <ul>
  <li>seems like my original approach above was not bad although it doesn't cover some corner cases, but that's fixable with a longer expression if you need to cover those</li>
  <li>another, slightly shorter approach uses regexps, which will be more or less readable depending on your regexp background</li>
  <li><p>a slightly shorter syntax for the original approach (corner cases not covered) reads:</p>
  
  <p><code>fileName.split('.').init :+ "js" mkString "."</code></p></li>
  </ul>