title: How can I remove non-numeric characters from strings using gsub in R?
body: <p>I use the <code>gsub</code> function in R to remove unwanted characters in numbers. So I should remove from the strings every character that is not a number, <code>.</code>, and <code>-</code>. My problem is that the regular expression is not removing some non-numeric characters like <code>d</code>, <code>+</code>, and <code>&lt;</code>.</p>
  
  <p>Below are my regular expression, the <code>gsub</code> execution, and its output. How can I change the regular expression in order to achieve the desired output?</p>
  
  <p><strong>Current output:</strong></p>
  
  <pre><code>gsub(pattern = '[^(-?(\\d*\\.)?\\d+)]', replacement = '', x = c('1.2&lt;', '&gt;4.5', '3+.2', '-1d0', '2aadddab2','1.3h'))
  [1] "1.2&lt;"  "&gt;4.5"  "3+.2"  "-1d0"  "2ddd2" "1.3"
  </code></pre>
  
  <p><strong>Desired output:</strong></p>
  
  <pre><code>[1] "1.2"  "4.5"  "3.2"  "-10"  "22" "1.3"
  </code></pre>
  
  <p>Thank you.</p>