title: Best Way to Extract Values from a String that can take many forms and is Loaded from a .properties file in Java
body: <p>I have a <strong>ws.properties</strong> file in which there's a property called <strong>success.code</strong> that gives me the option the choose which HTTP Status success codes (2xx), aside from the default 200, I want the server to treat as "Success" as well.</p>
  
  <p>The idea is like this:</p>
  
  <ol>
  <li>If I enter the value like this:</li>
  </ol>
  
  <blockquote>
    <p>success.code=201,202, 203 (values separated by a comma)</p>
  </blockquote>
  
  <p>The part of the code responsible for extracting this value should immediately understand that these are three separate codes, extract each one of them and store them in a list or set or....</p>
  
  <p>This is actually pretty easy:</p>
  
  <pre><code>private Set&lt;String[]&gt; getSuccessCodes(HashMap&lt;String, String&gt; codes){
      Set&lt;String[]&gt; successCodes = new HashSet&lt;&gt;();
      String value;
      for (Map.Entry&lt;String, String&gt; entry : codes.entrySet()) {
          value = entry.getValue();
          if(!StringUtils.isEmpty(value))
              successCodes.add(value.split("\\s*,\\s*"));
      }
      return successCodes;
  }
  </code></pre>
  
  <ol start="2">
  <li>Here's where it gets a little complicated:</li>
  </ol>
  
  <p>I would also like to add these options as well:</p>
  
  <blockquote>
    <p>success.code=[202, 220] (two values written between hooks and separated by a comma)</p>
  </blockquote>
  
  <ul>
  <li>[202, 220]: when the value is written like this, I want the above method to understand that I want all the values between 202 and 220 to be extracted, stored and returned like I did with the first case. </li>
  </ul>
  
  <blockquote>
    <p>success.code=2**</p>
  </blockquote>
  
  <ul>
  <li>This means that all the codes starting with 2 (so from 201 until 299) should be stored in a set or a list and returned back to me in that methods</li>
  </ul>
  
  <blockquote>
    <p>success.code=[200, 205], 22*</p>
  </blockquote>
  
  <ul>
  <li>this means that I want the code to return to me all the codes between 200 and 205 (so 200, 201, 202,.., 2005) plus the code that goes from 220 to 220.</li>
  </ul>
  
  <p>So depending on the value that I enter for the success code, the program should be able to understand what to do and what to return from it.</p>
  
  <p>Is this achievable? </p>
  
  <p>Thanks in advance</p>