title: Parsing time in minutes from String like "6m 5d3h "
body: <p>I wish to turn a String looking like this:</p>
  
  <pre><code>String string = "5d3h6m";
  </code></pre>
  
  <p>Or even like this:</p>
  
  <pre><code>String string = " 44h 22d";
  </code></pre>
  
  <p>In any order, and with any number of spaces into an <strong>int</strong> symbolising the time in minutes.</p>
  
  <p>(D=days H=Hours M=Minutes)</p>
  
  <p>The problems I have had:</p>
  
  <ol>
  <li>Finding the characters in any order</li>
  <li>Getting any number of digits that appear before the letter</li>
  </ol>
  
  <p>The following code is me trying to find a solution to the two problems (I am aware it is terrible code, that is why I am here, and no, I do not wish to be spoonfed):</p>
  
  <pre><code>if(timestring.contains(":")){
                              String[] timestringarray = timestring.split(":");
                              int timeinminutes = 0;
                              int timestringarraylength = timestringarray.length;
                              while(timestringarraylength&gt;0){ 
                                  if(timestringarray[timestringarraylength].matches("d{1}|D{1}")){
                                      timestring.replace("d{1}|D{1}","");
                                      long days = TimeUnit.MINUTES.convert(Integer.valueOf(timestring), TimeUnit.DAYS);
                                      int daysint = (int) (long) days;
                                      timeinminutes+=daysint;
                                  }
                                  if(timestringarray[timestringarraylength].matches("h{1}|H{1}")){
                                      timestring.replace("h{1}|H{1}","");
                                      long hours = TimeUnit.MINUTES.convert(Integer.valueOf(timestring), TimeUnit.HOURS);
                                      int hoursint = (int) (long) hours;
                                      timeinminutes+=hoursint;
                                  }
                                  if(timestringarray[timestringarraylength].matches("m{1}|M{1}")){
                                      timestring.replace("m{1}|M{1}","");
                                      long mins = TimeUnit.MINUTES.convert(Integer.valueOf(timestring), TimeUnit.MINUTES);
                                      int minsint = (int) (long) mins;
                                      timeinminutes+=minsint;
                                  }
                                  timestringarraylength--;
                              }
                              signConfig.set("Sign.time", Integer.valueOf(timeinminutes));
                          }
  </code></pre>
  
  <p>To specify, the String is a time entered by the user and won't change during the processing.<br>
  Thanks in advance.</p>