<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_quote">And this really is simple enough that I don't want to reach for regex's for it. That is, I'd write it by hand rather than mess with that.</div></div></blockquote></div></div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Well, with re.escape it's not messy at all :</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">import re</div><div dir="auto" class="">def trim_mailto(s):</div><div dir="auto" class="">  regex = re.compile("^" + re.escape("mailto:"))</div><div dir="auto" class="">  return regex.sub('', s)</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">With literally means "if you have mailto: at the beginning, replace it with the empty string"</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">You could do a ltrim function in one line :</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">def ltrim(s, x):</div><div dir="auto" class="">    return re.sub("^" + re.escape(x), '', s)</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">Escape will take care of escaping special characters, so the regex escape(x) matches exactly the string "x".</div><div dir="auto" class=""></div></div></div></blockquote><br class=""></div><div>I think</div><div><br class=""></div><div>    re.sub("^" + re.escape(x), '', s)</div><div><br class=""></div><div>is a lot more messy and hard to read than</div><div><br class=""></div><div>    s[len(prefix):] if s.startswith(prefix) else s </div><div><br class=""></div><div>it's also roughly an order of magnitude slower.</div><div><br class=""></div><div><br class=""></div><div>/ Anders</div><br class=""></body></html>