<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BitBonsai Labs &#187; python</title>
	<atom:link href="http://www.bitbonsai.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitbonsai.com</link>
	<description>Mauricio Wolff&#039;s geekness</description>
	<lastBuildDate>Tue, 18 Oct 2011 12:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python x PHP: Finding IPs with regex</title>
		<link>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/</link>
		<comments>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 12:09:47 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=147</guid>
		<description><![CDATA[Sometimes I just like to write code in Python and PHP to compare them, and admire both&#8230; Here&#8217;s a little code to find IP adressess inside strings (returned from a nslookup). The code is not optimal, but illustrate how both languages works. Just for some friday fun&#8230; Python &#160; Python 2.6.1 &#40;r261:67515, Jul  7 2009, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I just like to write code in Python and PHP to compare them, and admire both&#8230;</p>
<p>Here&#8217;s a little code to find IP adressess inside strings (returned from a nslookup). The code is not optimal, but illustrate how both languages works. Just for some friday fun&#8230;</p>
<h3>Python</h3>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
Python 2.6.1 <span style="color: black;">&#40;</span>r261:<span style="color: #ff4500;">67515</span>, Jul  <span style="color: #ff4500;">7</span> <span style="color: #ff4500;">2009</span>,  <span style="color: #ff4500;">23</span>:<span style="color: #ff4500;">51</span>:<span style="color: #ff4500;">51</span><span style="color: black;">&#41;</span>
 <span style="color: black;">&#91;</span>GCC 4.2.1 <span style="color: black;">&#40;</span>Apple Inc. <span style="color: black;">build</span> <span style="color: #ff4500;">5646</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> on darwin
 Type <span style="color: #483d8b;">&quot;help&quot;</span>, <span style="color: #483d8b;">&quot;copyright&quot;</span>, <span style="color: #483d8b;">&quot;credits&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;license&quot;</span>  <span style="color: #ff7700;font-weight:bold;">for</span>  more information.
&nbsp;
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a  = <span style="color: #483d8b;">'yahoo.com IN A 69.147.114.224 18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a += <span style="color: #483d8b;">'yahoo.com IN A 209.131.36.159 18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a += <span style="color: #483d8b;">'yahoo.com IN A 209.191.93.53  18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> a
 <span style="color: #483d8b;">'yahoo.com IN A 69.147.114.224  18774s (05:12:54)yahoo.com IN A 209.131.36.159 18774s  (05:12:54)yahoo.com IN A 209.191.93.53  18774s (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;;</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(?:<span style="color: #000099; font-weight: bold;">\d</span>{1,3}<span style="color: #000099; font-weight: bold;">\.</span>){3}<span style="color: #000099; font-weight: bold;">\d</span>{1,3}'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;;</span> p.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
 <span style="color: black;">&#91;</span><span style="color: #483d8b;">'69.147.114.224'</span>, <span style="color: #483d8b;">'209.131.36.159'</span>,  <span style="color: #483d8b;">'209.191.93.53'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span></pre></div></div>

<h3>PHP</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yahoo.com IN A 69.147.114.224 18774s (05:12:54)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'yahoo.com  IN A 209.131.36.159 18774s (05:12:54)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'yahoo.com  IN A 209.191.93.53  18774s (05:12:54)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
saida: yahoo.com IN A 69.147.114.224 18774s (05:12:54)yahoo.com IN A  209.131.36.159 18774s (05:12:54)yahoo.com IN A 209.191.93.53 18774s  (05:12:54)
*/</span>
&nbsp;
<span style="color: #000088;">$re</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/(\d+).(\d+).(\d+).(\d+)/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$re</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// saida 1</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// saida 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
saida 1:
&nbsp;
array(3) {
  [0]=&gt;
  string(14) &quot;69.147.114.224&quot;
  [1]=&gt;
  string(14) &quot;209.131.36.159&quot;
  [2]=&gt;
  string(13) &quot;209.191.93.53&quot;
}
&nbsp;
saida 2:
&nbsp;
array(5) {
  [0]=&gt;
  array(3) {
    [0]=&gt;
    string(14) &quot;69.147.114.224&quot;
    [1]=&gt;
    string(14) &quot;209.131.36.159&quot;
    [2]=&gt;
    string(13) &quot;209.191.93.53&quot;
  }
  [1]=&gt;
  array(3) {
    [0]=&gt;
    string(2) &quot;69&quot;
    [1]=&gt;
    string(3) &quot;209&quot;
    [2]=&gt;
    string(3) &quot;209&quot;
  }
  [2]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;147&quot;
    [1]=&gt;
    string(3) &quot;131&quot;
    [2]=&gt;
    string(3) &quot;191&quot;
  }
  [3]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;114&quot;
    [1]=&gt;
    string(2) &quot;36&quot;
    [2]=&gt;
    string(2) &quot;93&quot;
  }
  [4]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;224&quot;
    [1]=&gt;
    string(3) &quot;159&quot;
    [2]=&gt;
    string(2) &quot;53&quot;
  }
}
*/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

