title: How to get first integer between two specific characters with regex in Python?
body: <p>I'm parsing some log files and need to extract a integer for a "size" parameter.</p>
  
  <p>The string (part of it) looks like this</p>
  
  <pre><code> "asdasdasd\\\size\\x22:22\x0A23232d:123123123\x0A2"  
  </code></pre>
  
  <p>I want to get the first integer between ":" and "\". That would be 22. Not 123123123.</p>
  
  <p>I have tried the following code </p>
  
  <pre><code> p = re.compile("[\:](\d+)[\D]")
   s = "asdasdasd\\size\\x22:22\x0A23232d:123123123\x0A2"
   p.findall(s)[0]
  
   output = '22'
  </code></pre>
  
  <p>However, if there is no number between the first appearances of ":" and "\" and want the code to return None or 0. Right now the code will return '123123123' if the pattern looks like this:</p>
  
  <pre><code>"asdasdasd\\size\\x22:\x0A23232d:123123123\x0A2"
  </code></pre>
  
  <p>What would be the best way to achieve this?</p>