<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: The Joy of Regular Expressions [2]</title>
	<atom:link href="http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sun, 22 Nov 2009 11:54:05 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-608949</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Mon, 21 Jan 2008 20:07:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-608949</guid>
		<description>&lt;blockquote&gt;
if the filename has dots as separators in it the regexp won’t work
&lt;/blockquote&gt;

It would still work : &lt;code&gt;/^.*\.jpe?g$/i&lt;/code&gt; - all I&#039;m doing there is requiring the filename &lt;em&gt;ends&lt;/em&gt; with &lt;code&gt;.jpg&lt;/code&gt; or &lt;code&gt;.jpeg&lt;/code&gt; (case insenstive). otherwise you&#039;re allowed anything you like including . characters.</description>
		<content:encoded><![CDATA[<blockquote><p>
if the filename has dots as separators in it the regexp won’t work
</p></blockquote>
<p>It would still work : <code>/^.*\.jpe?g$/i</code> &#8211; all I&#8217;m doing there is requiring the filename <em>ends</em> with <code>.jpg</code> or <code>.jpeg</code> (case insenstive). otherwise you&#8217;re allowed anything you like including . characters.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Päse</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-608719</link>
		<dc:creator>Päse</dc:creator>
		<pubDate>Mon, 21 Jan 2008 15:07:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-608719</guid>
		<description>Nice examples! But you should check your &quot;Hunting for .jp(e)g&quot; because if the filename has dots as separators in it the regexp won&#039;t work ;-)</description>
		<content:encoded><![CDATA[<p>Nice examples! But you should check your &#8220;Hunting for .jp(e)g&#8221; because if the filename has dots as separators in it the regexp won&#8217;t work ;-)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: asdasdasd</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-85095</link>
		<dc:creator>asdasdasd</dc:creator>
		<pubDate>Tue, 07 Nov 2006 22:42:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-85095</guid>
		<description>&lt;blockquote&gt;What’s interesting is str_replace performs better in this case, but only significantly so if the “replace” target is a string—not an array&lt;/blockquote&gt;</description>
		<content:encoded><![CDATA[<blockquote><p>What’s interesting is str_replace performs better in this case, but only significantly so if the “replace” target is a string—not an array</p></blockquote>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-75316</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Fri, 27 Oct 2006 21:09:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-75316</guid>
		<description>&lt;blockquote&gt;
Great article, and thanks for the bit on eval()—I never knew of its security flaws over and above the obvious injection attacks.

By the way, the link to sprintf() on php.net is incorrect here—it links to http://php.nett/sprintf. 
&lt;/blockquote&gt;

Thanks and thanks - now fixed at last.</description>
		<content:encoded><![CDATA[<blockquote><p>
Great article, and thanks for the bit on eval()—I never knew of its security flaws over and above the obvious injection attacks.</p>
<p>By the way, the link to sprintf() on php.net is incorrect here—it links to <a href="http://php.nett/sprintf" rel="nofollow">http://php.nett/sprintf</a>.
</p></blockquote>
<p>Thanks and thanks &#8211; now fixed at last.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-61506</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Fri, 29 Sep 2006 14:59:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-61506</guid>
		<description>Great article, and thanks for the bit on eval() - I never knew of its security flaws over and above the obvious injection attacks.

By the way, the link to sprintf() on php.net is incorrect &lt;a href=&quot;#preg_replace_callback&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; - it links to http://php.net&lt;strong&gt;t&lt;/strong&gt;/sprintf.</description>
		<content:encoded><![CDATA[<p>Great article, and thanks for the bit on eval() &#8211; I never knew of its security flaws over and above the obvious injection attacks.</p>
<p>By the way, the link to sprintf() on php.net is incorrect <a href="#preg_replace_callback" rel="nofollow">here</a> &#8211; it links to <a href="http://php.net" rel="nofollow">http://php.net</a><strong>t</strong>/sprintf.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: 1magic</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60848</link>
		<dc:creator>1magic</dc:creator>
		<pubDate>Wed, 27 Sep 2006 15:01:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60848</guid>
		<description>Nice article series. Thanks!</description>
		<content:encoded><![CDATA[<p>Nice article series. Thanks!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Selkirk</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60846</link>
		<dc:creator>Selkirk</dc:creator>
		<pubDate>Wed, 27 Sep 2006 14:53:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60846</guid>
		<description>Nice article.  There is also another problem with escaping the replacement parameter of preg_replace under certain conditions.  preg_quote is not suitable for that task because it is geared toward the search parameter and not the replacement parameter.  I talk about that and the e modifier in my blog post on &lt;a href=&quot;http://www.procata.com/blog/archives/2005/11/13/two-preg_replace-escaping-gotchas/&quot; rel=&quot;nofollow&quot;&gt;preg_replace escaping&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Nice article.  There is also another problem with escaping the replacement parameter of preg_replace under certain conditions.  preg_quote is not suitable for that task because it is geared toward the search parameter and not the replacement parameter.  I talk about that and the e modifier in my blog post on <a href="http://www.procata.com/blog/archives/2005/11/13/two-preg_replace-escaping-gotchas/" rel="nofollow">preg_replace escaping</a>.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60754</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Wed, 27 Sep 2006 10:08:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60754</guid>
		<description>&lt;blockquote&gt;
Harry, didn&#039;t you mean str_replace?
&lt;/blockquote&gt;

Well I meant strtr() (the example works) based on the unconfirmed theory that it would offer better performance than str_replace(). But looking at &lt;a href=&quot;http://ilia.ws/files/phpworks_performance.pdf&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; (see str_replace vs. strtr later on) reminds me it&#039;s best always to question &quot;accepted performance wisdom&quot; with benchmarks.

What&#039;s interesting is str_replace performs better in this case, but only significantly so if the &quot;replace&quot; target is a string - not an array

Fastest:

&lt;code&gt;$str = str_replace(array( &quot;\r\n&quot;,&quot;\n&quot;), &quot;\n&quot;, $str);&lt;/code&gt;

About the same:

&lt;code&gt;$str = str_replace(array( &quot;\r\n&quot;,&quot;\n&quot;), array(&quot;\n&quot;,&quot;\n&quot;), $str);&lt;/code&gt;

&lt;code&gt;$str = strtr($str, array( &quot;\r\n&quot;=&gt;&quot;\n&quot; , &quot;\r&quot;=&gt;&quot;\n&quot; ));&lt;/code&gt;

Even more excitement - doing two &lt;em&gt;seperate&lt;/em&gt; strtr&#039;s seems to match the performance of the fastest str_replace above;

&lt;code&gt;
$str = strtr($str, &quot;\r\n&quot;, &quot;\n&quot;);
$str = strtr($str, &quot;\r&quot;, &quot;\n&quot;);
&lt;/code&gt;

...but used pretty short $str&#039;s so that may not scale to bigger documents.

Side note: additional confusion is being caused in these examples by the comment feature adding slashes to quotes :(</description>
		<content:encoded><![CDATA[<blockquote><p>
Harry, didn&#8217;t you mean str_replace?
</p></blockquote>
<p>Well I meant strtr() (the example works) based on the unconfirmed theory that it would offer better performance than str_replace(). But looking at <a href="http://ilia.ws/files/phpworks_performance.pdf" rel="nofollow">this</a> (see str_replace vs. strtr later on) reminds me it&#8217;s best always to question &#8220;accepted performance wisdom&#8221; with benchmarks.</p>
<p>What&#8217;s interesting is str_replace performs better in this case, but only significantly so if the &#8220;replace&#8221; target is a string &#8211; not an array</p>
<p>Fastest:</p>
<code>$str = str_replace(array( "\r\n","\n"), "\n", $str);</code>
<p>About the same:</p>
<code>$str = str_replace(array( "\r\n","\n"), array("\n","\n"), $str);</code>
<code>$str = strtr($str, array( "\r\n"=&gt;"\n" , "\r"=&gt;"\n" ));</code>
<p>Even more excitement &#8211; doing two <em>seperate</em> strtr&#8217;s seems to match the performance of the fastest str_replace above;</p>
<code>
$str = strtr($str, "\r\n", "\n");
$str = strtr($str, "\r", "\n");
</code>
<p>&#8230;but used pretty short $str&#8217;s so that may not scale to bigger documents.</p>
<p>Side note: additional confusion is being caused in these examples by the comment feature adding slashes to quotes :(</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Manders</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60729</link>
		<dc:creator>Maarten Manders</dc:creator>
		<pubDate>Wed, 27 Sep 2006 09:29:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60729</guid>
		<description>The replacement doesn&#039;t need to be an array, just &quot;\n&quot;, if i remember correctly.</description>
		<content:encoded><![CDATA[<p>The replacement doesn&#8217;t need to be an array, just &#8220;\n&#8221;, if i remember correctly.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Manders</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60728</link>
		<dc:creator>Maarten Manders</dc:creator>
		<pubDate>Wed, 27 Sep 2006 09:28:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60728</guid>
		<description>Harry, didn&#039;t you mean str_replace? For normalization we&#039;re using

&lt;pre&gt;&lt;code class=&#039;php&#039;&gt;  
str_replace(array(&quot;\r\n&quot;, &quot;\r&quot;), array(&quot;\n&quot;, &quot;\n&quot;), $input)
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Harry, didn&#8217;t you mean str_replace? For normalization we&#8217;re using</p>
<pre><code class='php'>  
str_replace(array("\r\n", "\r"), array("\n", "\n"), $input)
</code></pre>]]></content:encoded>
	</item>
</channel>
</rss>
