title: Split a string on backslash when backslashes are followed by numbers
body: <p>I have some filenames in a directory, all named like '.\subreddits\somename\somename.db'.<br>
  One of these files has a number following the backslashes:    </p>
  
  <p>.\subreddits\600euro\600euro.db</p>
  
  <p>I want to<br>
      * iterate through all files in the dir,<br>
      * get the middle element/or last element of each filename<br>
      * open the file, ie open an sql connection to it. </p>
  
  <p>I cannot split the filename of that one file with the numbers after the backslashes:</p>
  
  <pre><code>for db in os.listdir(dir_with_dbs):
      print(db) # .\subreddits\600euro\600euro.db -&gt; .\subredditsƀeuroƀeuro.db
      # get middle name of db file: .\subreddits\xy\xy.db -&gt; xy
      # THIS FAILS on the backslash-number combination:
      out_str = db.split("\\")[2] # list index out of range
  
      # open file that will contain results: query_res_xy
      with open("query_res_" + out_str, 'w') as out:
  
          #execute a query on the db file
          conn = sqlite3.connect(os.path.join(dir_with_dbs, db))          
          c = conn.cursor()
          c.execute(query)
  
          # write results of query to file with same middle/last name
          for row in c.fetchall():
              out.write(row + '\n')
  </code></pre>
  
  <p>This question <a href="https://stackoverflow.com/questions/20716676/how-to-manage-a-path-with-numbers-after-backslashes">How to manage a path with numbers after backslashes?</a> describes a similar problem, but OP didn't want to change/split the string.<br>
  I cannot rename the files and I do not know beforehand which files are in the dir.    </p>
  
  <p>How can I get python to recognize the backslashes even when numbers come after them? Or how else could I get the middle/last element of the filenames?</p>
  
  <p>I have also tried to encode() + decode() the filenames, but I cannot retrieve the numbers in the string.</p>