title: How can I create a nonnegative integer regular expression?
body: <p>I want to compile a <code>Pattern</code> that matches nonnegative integers. It should look for a sequence of one or more consecutive digits that is not preceded by another digit or a negative sign. I have been able to compile the following:</p>
  
  <pre><code>Pattern digit = Pattern.compile("\\d");  //looks for single digits
  </code></pre>
  
  <p>But suppose I declare the following:</p>
  
  <pre><code>String a = "90 210";
  String b = "-90 210";
  String c = "z90p210";
  String d = "pz-90210";
  </code></pre>
  
  <p><code>digit</code> would match <code>"9"</code>, <code>"0"</code>, <code>"2"</code>, <code>"1"</code>, and <code>"0"</code> in all four of these. I'm interested in a <code>Pattern</code> that would match <code>"90"</code> and <code>"210"</code> in <code>a</code>, <code>"210"</code> in <code>b</code>, <code>"90"</code> and <code>"210"</code> in <code>c</code>, and would not match anything in <code>d</code>.</p>
  
  <p>Is there a way to disregard sequences of digits preceded by a negative sign or another digit? </p>