title: Get Substring of A String with Spaces and Quotes using IndexOf
body: <p>I have the following String and would like to extract the contents of rule i.e. My Rule Description Looks Like This:</p>
  
  <pre><code>rule "My Rule Description Looks Like This"      
          followed by some white space other characters such as quotes".
  </code></pre>
  
  <p>When i use the following I get a java.lang.StringIndexOutOfBoundsException: String index out of range: -2:</p>
  
  <pre><code>String ruleName = rule.substring(rule.indexOf("rule \"" + 7, rule.indexOf("\""));
  </code></pre>
  
  <p>and when i use lastIndexOf:</p>
  
  <pre><code>String ruleName = rule.substring(rule.indexOf("rule \"" + 7, rule.lastIndexOf("\""));
  </code></pre>
  
  <p>the code executes OK but the output looks like:</p>
  
  <pre><code>My Rule Description Looks Like This"        
          followed by some white space other characters and quotes
  </code></pre>
  
  <p>Any ideas why the first option throws an exception using indexOf?</p>