<div dir="ltr"><div class="gmail_default" style="color:#000000"><br></div><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 4, 2013 at 8:39 AM, Roy Smith <span dir="ltr"><<a href="mailto:roy@panix.com" target="_blank">roy@panix.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In article <<a href="mailto:mailman.96.1365077619.3114.python-list@python.org">mailman.96.1365077619.3114.python-list@python.org</a>>,<br>

<div class="im"> Jason Swails <<a href="mailto:jason.swails@gmail.com">jason.swails@gmail.com</a>> wrote:<br>
<br>
> The only time I regularly break my rule is for regular expressions (at some<br>
> point I may embrace re.X to allow me to break those up, too).<br>
<br>
</div>re.X is a pretty cool tool for making huge regexes readable.  But, it<br>
turns out that python's auto-continuation and string literal<br>
concatenation rules are enough to let you get much the same effect.<br>
Here's a regex we use to parse haproxy log files. This would be utter<br>
line noise all run together. This way, it's almost readable :-)<br>
<br>
pattern = re.compile(r'haproxy\[(?P<pid>\d+)]: '<br>
                     r'(?P<client_ip>(\d{1,3}\.){3}\d{1,3}):'<br>
                     r'(?P<client_port>\d{1,5}) '<br></blockquote><div><br></div><div style="color:rgb(0,0,0)" class="gmail_default">For some reason that never occurred to me.  I use this technique every other time I want to break up a long string, but never for regexes...</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">Now I will.  I was wary of using re.X since I sometimes use meaningful whitespace in my regexes, and I didn't want to have to figure out how to prevent them from being ignored...  This is a much better solution.</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">Thanks,</div><div style="color:rgb(0,0,0)" class="gmail_default">Jason</div></div></div></div>