Finding pairs of numbers in substring with regex
<p>I need to find max subsequence of specified format like </p>

<blockquote>
  <p>[a,b],[c,d] (b>a and c>d) </p>
</blockquote>

<p>My algorithm works fine. But when i try to split input string in format <strong>\d{2}</strong> it splits me by one digit. How to fix it! Help, pls!</p>

<p>Here is my main class.</p>

<pre><code>    /**
 * 
 */
package pack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author serg_shapoval
 *
 */
public class Pairs {

    public static String pairs(String input) {
        List&lt;Pair&gt; list = new ArrayList&lt;&gt;();
        List&lt;Pair&gt; tempList = new ArrayList&lt;&gt;();
        List&lt;Pair&gt; maxSubqueryList = new ArrayList&lt;&gt;();
        String[] inputArr = input.split("\\d{2}");
        System.out.println(Arrays.toString(inputArr));
        for (int i = 0; i &lt; inputArr.length; i++) {
            Pair p = new Pair();
            p.setFirstNumber(inputArr[i].charAt(1));
            p.setSecondNumber(inputArr[i].charAt(2));
            list.add(p);
        }
        if (list.isEmpty()) {
            return "null";
        }
        for (int i = 0; i &lt; list.size(); i++) {
            if (list.get(i).getFirstNumber() &lt; list.get(i).getSecondNumber()
                    &amp;&amp; list.get(i + 1).getFirstNumber() &gt; list.get(i + 1).getSecondNumber()) {
                tempList.add(list.get(i));
                tempList.add(list.get(i + 1));
            }

            if (tempList.size() &gt;= maxSubqueryList.size()) {
                maxSubqueryList.clear();
                maxSubqueryList.addAll(tempList);
                tempList.clear();

            }
        }

        return maxSubqueryList.toString();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(pairs("12 34 45 32 12 45 32 4 55 6"));
    }

}
</code></pre>

<p>And here my Pair class.</p>

<pre><code>    /**
 * 
 */
package pack;

/**
 * @author serg_shapoval
 *
 */
public class Pair {

    private int firstNumber;
    private int secondNumber;
    /**
     * @return the firstNumber
     */
    public int getFirstNumber() {
        return firstNumber;
    }
    /**
     * @param firstNumber the firstNumber to set
     */
    public void setFirstNumber(int firstNumber) {
        this.firstNumber = firstNumber;
    }
    /**
     * @return the secondNumber
     */
    public int getSecondNumber() {
        return secondNumber;
    }
    /**
     * @param secondNumber the secondNumber to set
     */
    public void setSecondNumber(int secondNumber) {
        this.secondNumber = secondNumber;
    }




}
</code></pre>

<p>Here is my output using this string "12 34 45 32 12 45 32 4 55 6"</p>

<blockquote>
  <p>[,  ,  ,  ,  ,  ,  ,  4 ,  6]
  Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
      at java.lang.String.charAt(String.java:658)
      at pack.Pairs.pairs(Pairs.java:24)
      at pack.Pairs.main(Pairs.java:53)</p>
</blockquote>