title: Extracting a word from a message in java
body: <p>I have a message that is of the format:</p>
  
  <pre><code>FixedWord1 variable1 FixedWord2 on FixedWord3 variable2/variable3, variable4 = variable5
  </code></pre>
  
  <p>I need to extract only variable3 from the above message.</p>
  
  <p>Here is what I tried:  </p>
  
  <pre><code>String example = "FixedWord1 variable1 FixedWord2 on FixedWord3 variable2/variable3, variable4 = variable5";
  </code></pre>
  
  <p>I know that the length of FixedWord3 is 6. So, </p>
  
  <pre><code>example.substring(example.lastIndexOf("FixedWord3") + 6 , example.lastIndexOf(","));  //To get {variable2}/{variable3}
  </code></pre>
  
  <p>And then,</p>
  
  <pre><code>String requiredString[] = example.split("/", 2);  //requiredString[1] would contain {variable3} even if it contains /
  </code></pre>
  
  <p>Can you suggest a more efficient solution to this problem?</p>