title: Tokenize string in python using regular expression
body: <p>I've input data in the following format, not decided by me</p>
  
  <pre><code>key1: value1 key2: value2 key3: value3 key4 { key11: val11 key22: value22 } key5: value5 ............
  </code></pre>
  
  <p>The input string will have key values separated by colon or a brace bracket.</p>
  
  <p>I want to tokenize it and I have the following idea:
  First to have a regular expression parsing data till I find a <code>:</code> or <code>{</code> with priority to <code>{</code> over <code>:</code></p>
  
  <p>Then split and read till the white space pattern that I said is reached and recursively traverse the whole string</p>
  
  <p>I want to know if I can write a regex like (some_string)(special character pattern)
  (special character pattern can be <code>:</code> or <code>{</code> with precedence to <code>{</code>)(rest of the string)</p>
  
  <p>If it is a <code>:</code> then for rest of the string, get the string part from ' value1 ' and capture it. Work on the remaining string</p>
  
  <p>If it is a <code>{</code> then traverse till you find <code>}</code> and internally work with <code>:</code> logic defined above.</p>
  
  <p>For eg</p>
  
  <pre><code>a: 1 b: 2 c { d: 3 e: 4 } f: 5
  </code></pre>
  
  <p>This should give </p>
  
  <pre><code>a:1
  b:2
  c { d: 3 e: 4 }
  f: 5
  </code></pre>