title: Need help Translating PHP to Python
body: <p>I am using a REST library whose development team only supports PHP. Pretty much everything are finished except translating this part of their PHP code to my Python codebase. the "preg_match" is tough for me, please help.</p>
  
  <p>Their PHP:</p>
  
  <pre><code>function strippadding($string) {
    $slast  = ord(substr($string, -1));
    $slastc = chr($slast);
    $pcheck = substr($string, -$slast);
    if (preg_match("/$slastc{" . $slast . "}/", $string)) {
      $string = substr($string, 0, strlen($string) - $slast);
      return $string;
    } else {
      return false;
    }
  }
  </code></pre>
  
  <p>My Python:</p>
  
  <pre><code>def strip_padding_pay2go(string):
    last_string = string[-1]
    slast       = ord(last_string)
    slastc      = chr(slast)
    pcheck      = last_string[:-slast]
  
    if re.search("/" + str(slastc) + "{" + str(slast) + "}/", string):
        last_char =  len(string) - slast
        new_string = string[0: last_char]
        return new_string
    else:
        return False
  </code></pre>
  
  <p>But i keep failing ( returns False ).</p>