title: Creating regex to extract 4 digit number from string using java
body: <p>Hi I am trying to build one regex to extract 4 digit number from given string using java. I tried it in following ways:</p>
  
  <pre><code>String mydata = "get the 0025 data from string";
      Pattern pattern = Pattern.compile("^[0-9]+$");
      //Pattern pattern = Pattern.compile("^[0-90-90-90-9]+$");
      //Pattern pattern = Pattern.compile("^[\\d]+$");
      //Pattern pattern = Pattern.compile("^[\\d\\d\\d\\d]+$");
  
      Matcher matcher = pattern.matcher(mydata);
      String val = "";
      if (matcher.find()) {
          System.out.println(matcher.group(1));
  
          val = matcher.group(1);
      }
  </code></pre>
  
  <p>But it's not working properly. How to do this. Need some help. Thank you.</p>