title: Python Regex: Remove optional characters
body: <p>I have a regex pattern with optional characters however at the output I want to remove those optional characters. Example: </p>
  
  <pre><code>string = 'a2017a12a'    
  pattern =  re.compile("((20[0-9]{2})(.?)(0[1-9]|1[0-2]))")
  result = pattern.search(string)
  print(result)
  </code></pre>
  
  <p>I can have a match like this but what I want as an output is:</p>
  
  <pre><code>desired output = '201712'
  </code></pre>
  
  <p>Thank you. </p>