title: Python: String formatting a regex string that uses both '%' and '{' as characters
body: <p>I have the following regular expression, which lets me parse percentages like '20%+', '20%', or '20% - 50%' using re.split.</p>
  
  <pre><code>'([0-9]{1,3}[%])([+-]?)'
  </code></pre>
  
  <p>I want to use string formatting to pass the series identifiers (i.e. '+-') as an argument from config.py.</p>
  
  <pre><code>SERIES = '+-'
  </code></pre>
  
  <p>The two methods I've tried produced errors. New-style formatting runs into the following error (due to the {m,n} usage):</p>
  
  <pre><code>&gt;&gt;&gt; import config
  &gt;&gt;&gt; regex = '([0-9]{1,3}[%])([{0}]?)'.format(config.SERIES)
  KeyError: '1,3'
  </code></pre>
  
  <p>Old-style formatting has its own problems (due to the '%' character):</p>
  
  <pre><code>&gt;&gt;&gt; import config
  &gt;&gt;&gt; regex = '([0-9]{1,3}[%])([%s]?)' % (config.SERIES)
  unsupported format character ']' (0x5d) at index 14
  </code></pre>
  
  <p>I haven't been able to get escape characters working inside the regex. Any ideas on how do do this?</p>
  
  <p>Thanks,</p>
  
  <p>Mike</p>