title: Java - Extract strings with Regex
body: <p>I've this string</p>
  
  <pre><code>String myString ="A~BC~FGH~~zuzy|XX~ 1234~ ~~ABC~01/01/2010 06:30~BCD~01/01/2011 07:45";
  </code></pre>
  
  <p>and I need to extract these 3 substrings<br>
  <strong>1234</strong><br>
  <strong>06:30</strong><br>
  <strong>07:45</strong><br>
  <br>
  If I use this regex \\d{2}\:\\d{2}  I'm only able to extract the first hour 06:30</p>
  
  <pre><code>Pattern depArrHours = Pattern.compile("\\d{2}\\:\\d{2}");
  Matcher matcher = depArrHours.matcher(myString);
  String firstHour = matcher.group(0);
  String secondHour = matcher.group(1); (IndexOutOfBoundException no Group 1)
  </code></pre>
  
  <p>matcher.group(1) throws an exception.<br>
  Also I don't know how to extract 1234. This string can change but it always comes after 'XX~ ' <br>
  Do you have any idea on how to match these strings with regex expressions? </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to Adam suggestion I've now this regex that match my string</p>
  
  <pre><code>Pattern p = Pattern.compile(".*XX~ (\\d{3,4}).*(\\d{1,2}:\\d{2}).*(\\d{1,2}:\\d{2})";
  </code></pre>
  
  <p>I match the number, and the 2 hours with matcher.group(1); matcher.group(2); matcher.group(3);</p>