title: return only Digits 0-9 from a String
body: <p>I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string. </p>
  
  <p>For Example any of the following "strings" should return only <strong>1231231234</strong></p>
  
  <ul>
  <li>123 123 1234</li>
  <li>(123) 123-1234</li>
  <li>123-123-1234</li>
  <li>(123)123-1234</li>
  <li>123.123.1234</li>
  <li>123  123 1234</li>
  <li>1 2 3 1 2 3 1 2 3 4</li>
  </ul>
  
  <p>This will be used in an email parser to find telephone numbers that customers may provide in the email and do a database search.</p>
  
  <p>I may have missed a similar regex but I did search on regexlib.com.</p>
  
  <p>[EDIT] - Added code generated by <a href="http://www.regexbuddy.com/" rel="noreferrer">RegexBuddy</a> after setting up musicfreak's answer</p>
  
  <p><strong>VBScript Code</strong></p>
  
  <pre><code>Dim myRegExp, ResultString
  Set myRegExp = New RegExp
  myRegExp.Global = True
  myRegExp.Pattern = "[^\d]"
  ResultString = myRegExp.Replace(SubjectString, "")
  </code></pre>
  
  <p><strong>VB.NET</strong></p>
  
  <pre><code>Dim ResultString As String
  Try
        Dim RegexObj As New Regex("[^\d]")
        ResultString = RegexObj.Replace(SubjectString, "")
  Catch ex As ArgumentException
        'Syntax error in the regular expression
  End Try
  </code></pre>
  
  <p><strong>C#</strong></p>
  
  <pre><code>string resultString = null;
  try {
      Regex regexObj = new Regex(@"[^\d]");
      resultString = regexObj.Replace(subjectString, "");
  } catch (ArgumentException ex) {
      // Syntax error in the regular expression
  }
  </code></pre>