title: Searching for a pattern in a string
body: <p>I have an input string as below:</p>
  
  <pre><code>john is a StartDate 10\11\2012 EndDate 15\11\2012 john is a boy john is StartDate john
  </code></pre>
  
  <p>I want to extract the two dates StartDate and EndDate from above string. </p>
  
  <p>However, I can not just search for word StartDate because as seen towards the end of the string, StartDate may come as an independent word. I can not take first instance because there is no gaurantee that StartDate word with the dates will always be first. </p>
  
  <p>So solution would be to search for pattern StartDate % EndDate % together.  i.e. both StartDate and EndDate words together. </p>
  
  <p>What would be the best way to achieve this? </p>
  
  <p>One solution I can think of is for every instance of word StartDate, take the substring of next four words (including StartDate) and search for word EndDate in that subString. If its exists, we have the correct substring else go for the next instance of StartDate word and repeat the task. </p>