<!--/*SC*/DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"/*EC*/-->
<html><head><title></title><style type="text/css"><!--body{padding:1ex;margin:0px;font-family:sans-serif;font-size:small;}a[href]{color:-moz-hyperlinktext !important;text-decoration:-moz-anchor-decoration;}blockquote{margin:0;border-left:2px solid #144fae;padding-left:1em;}blockquote blockquote{border-color:#006312;}blockquote blockquote blockquote{border-color:#540000;}--></style></head><body><div style="font-family: Arial; font-size: medium;" dir="ltr"><div>I'm looking for a pythonic way to trim and keep leading whitespace in a string.</div>
<div> </div>
<div>Use case: I have a bunch of text strings with various amounts of leading and trailing whitespace (spaces and tabs). I want to grab the leading and trailing whitespace, save it, surround the remaining text with html tags, and then add back the leading and trailing whitespace.</div>
<div> </div>
<div>The only solution I can think of is regex, and that makes me think of the 2 proverbial problems that come with that :)</div>
<div> </div>
<div>Is there a 'better' solution than regex for this scenario? (Seems like this would be a common type of string processing).</div>
<div> </div>
<div>Thanks,</div>
<div>Malcolm</div>
<div> </div>
<div> </div></div></body></html>