title: Replacing all characters that are not digits, commas or dots using regular expression
body: <p>Here's what I was doing:</p>
  
  <pre><code>public static String replaceCharAt(String s, int pos, char c) {
      return s.substring(0, pos) + c + s.substring(pos + 1);
    }
  
  for(int i=0;i&lt;str.length();i++)
  {
      if(str.charAt(i)!=',' || str.charAt(i)!='.' || !Character.isDigit(str.charAt(i)))
           replaceCharAt(str,i,'x');
  }
  </code></pre>
  
  <p>but I've been told that regular expressions are way more effective. Unfortunately I don't know how to use regex, I'm just learning for the very first time.</p>
  
  <p>This is the regex I'm using to replace all non-digit characters</p>
  
  <pre><code>str.replaceAll("\\D", "")
  </code></pre>
  
  <p>but how can I make dots and commas not being removed?</p>