title: How do I match any non-word character at the end of a line or just the end of the line
body: <p>Using regex, I want to match all non-word characters at the end of a line, or, if there isn't a non-word character, just match the end of the line.</p>
  
  <p>This is what I thought it should be as simple as:</p>
  
  <pre><code>/\W*$/
  </code></pre>
  
  <p>That is, match zero or more non-word characters, followed by the end of the line.</p>
  
  <p>I tried it at <a href="http://gskinner.com/RegExr/" rel="nofollow">http://gskinner.com/RegExr/</a> but it's not that simple.</p>
  
  <p>Then, taking it one step further, I also want to match white space at the end of the line, like this:</p>
  
  <pre><code>/[\W\s]*$/
  </code></pre>
  
  <p>That is, match zero or more characters from the set, non-word characters and white space characters, followed by the end of the line.</p>
  
  <p>Of course, this isn't working either.</p>
  
  <p>At the end of the day I want to replace anything at the end of a line that is not an alphanumeric character with a full stop, using javascript.</p>