title: Extract Substring from String java
body: <p>I want to extract specific substrings from a string:</p>
  
  <pre><code>String source = "info1 info1ContentA info1ContentB info3 info3ContentA info3ContentB"+
  "info2 info2ContentA";
  </code></pre>
  
  <p>The result should be:</p>
  
  <pre><code>String info1 ="info1ContentA info1ContentB";
  String info2 ="info2ContentA";
  String info3 ="info3ContentA info3ContentB";
  </code></pre>
  
  <p>For me it's very difficult to extract the informations, because sometimes after "info" their are one, two or more content informations. Another problem that occurs is, that the order of info1, info2 etc. is not sorted and the "real data" doesn't contain a ascending number.</p>
  
  <p>My first idea was to add info1, info2, info3 etc to an ArrayList.</p>
  
  <pre><code>private ArrayList&lt;String&gt; arr = new ArrayList&lt;String&gt;();
  arr.add("info1");
  arr.add("info2");
  arr.add("info3");
  </code></pre>
  
  <p>Now I want to extract the substring with the method StringUtils.substringBetween() from Apache Commons (<a href="https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.4" rel="nofollow noreferrer">https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.4</a>):</p>
  
  <pre><code>String result = StringUtils.substringBetween(source, arr.get(0), arr.get(1));
  </code></pre>
  
  <p>This works, if info1 is in the string before info2, but like I said the "real data" is not sorted. </p>
  
  <p>Any idea how I can fix this?</p>