title: How to negate a regex pattern to be used with String replaceAll method?
body: <p>I wish to get a string that only accepts lowercase alphanumeric characters or <code>-</code>. If the string contains any other character it should be replaced with a <code>-</code>. </p>
  
  <p>I tried the below regex with look-ahead negation but it appends an extra <code>-</code> in the end. How can I fix this?  </p>
  
  <pre><code>public string sampleTest() {
    String name = "test-7657-hello.WOrld"
    return name.toLowerCase().replaceAll("(?![a-z0-9]([-a-z0-9]*[a-z0-9])?)", "-")
  }
  </code></pre>
  
  <p>For eg: Should replace the dot with <code>-</code> in the above example.</p>