<?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>Fri, 19 Mar 2010 02:31:55 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</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>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60726</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Wed, 27 Sep 2006 09:23:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60726</guid>
		<description>&lt;blockquote&gt;
Is there an easy way to explicitly match linebreaks, no matter whether they’re unix/windows/mac style?
&lt;/blockquote&gt;

Don&#039;t have a generic solution off-hand so if you&#039;ve got one, feel free to blow my mind ;)

Somehow think it&#039;s probably best to normalize to \n before starting to use regexs, given this is what the . metacharacter &quot;understands&quot; (controlled by the /s pattern modifier).

But if you wanted to split a string into lines, without caring what kind of linebreaks you&#039;re dealing with, this should work;

&lt;code&gt;
$lines = preg_split(&#039;/\r\n?&#124;\n/&#039;, $text);
&lt;/code&gt;

To normalize up front, using strtr should be pretty efficient;

&lt;code&gt;
$text = strtr($text, array( &quot;\r\n&quot;=&gt;&quot;\n&quot; , &quot;\r&quot;=&gt;&quot;\n&quot; ));
&lt;/code&gt;
</description>
		<content:encoded><![CDATA[<blockquote><p>
Is there an easy way to explicitly match linebreaks, no matter whether they’re unix/windows/mac style?
</p></blockquote>
<p>Don&#8217;t have a generic solution off-hand so if you&#8217;ve got one, feel free to blow my mind ;)</p>
<p>Somehow think it&#8217;s probably best to normalize to \n before starting to use regexs, given this is what the . metacharacter &#8220;understands&#8221; (controlled by the /s pattern modifier).</p>
<p>But if you wanted to split a string into lines, without caring what kind of linebreaks you&#8217;re dealing with, this should work;</p>
<code>
$lines = preg_split('/\r\n?|\n/', $text);
</code>
<p>To normalize up front, using strtr should be pretty efficient;</p>
<code>
$text = strtr($text, array( "\r\n"=&gt;"\n" , "\r"=&gt;"\n" ));
</code>]]></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-60692</link>
		<dc:creator>Maarten Manders</dc:creator>
		<pubDate>Wed, 27 Sep 2006 07:30:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60692</guid>
		<description>Is there an easy way to explicitly match linebreaks, no matter whether they&#039;re unix/windows/mac style?</description>
		<content:encoded><![CDATA[<p>Is there an easy way to explicitly match linebreaks, no matter whether they&#8217;re unix/windows/mac style?</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-60690</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Wed, 27 Sep 2006 07:25:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60690</guid>
		<description>&lt;blockquote&gt;
But to call it evil because it&#039;s &quot;insecure&quot; is inaccurate.
&lt;/blockquote&gt;

Agreed - it&#039;s just another tool. The &quot;eval() is evil&quot; mantra is much like the &quot;you must normalize your dbs to the nth form&quot; - for starters is saves the need for long discussion and it&#039;s also encouraging certain practices - what&#039;s less often discussed is when you&#039;d want to denormalize your db schemas, often for efficiency, but &quot;denormalize your tables!&quot; or &quot;eval is OK sometimes&quot; is not something you hear.

Think the particular danger here is the /e modifier helps you write a neat one-liner while preg_replace_callback is less &quot;elegant&quot; (relative term) - that might catch out people who&#039;d no better otherwise.</description>
		<content:encoded><![CDATA[<blockquote><p>
But to call it evil because it&#8217;s &#8220;insecure&#8221; is inaccurate.
</p></blockquote>
<p>Agreed &#8211; it&#8217;s just another tool. The &#8220;eval() is evil&#8221; mantra is much like the &#8220;you must normalize your dbs to the nth form&#8221; &#8211; for starters is saves the need for long discussion and it&#8217;s also encouraging certain practices &#8211; what&#8217;s less often discussed is when you&#8217;d want to denormalize your db schemas, often for efficiency, but &#8220;denormalize your tables!&#8221; or &#8220;eval is OK sometimes&#8221; is not something you hear.</p>
<p>Think the particular danger here is the /e modifier helps you write a neat one-liner while preg_replace_callback is less &#8220;elegant&#8221; (relative term) &#8211; that might catch out people who&#8217;d no better otherwise.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: binjured</title>
		<link>http://www.sitepoint.com/blogs/2006/09/27/the-joy-of-regular-expressions-2/comment-page-1/#comment-60660</link>
		<dc:creator>binjured</dc:creator>
		<pubDate>Wed, 27 Sep 2006 04:46:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=1721#comment-60660</guid>
		<description>&quot;The moment you hear eval() the word “evil” should be on the tip of your tongue&quot;

I believe more accurately, the moment you hear eval() the words &quot;poor programmers&quot; should be on the tip of your tongue.  While I believe in this case, and really any case where smarter alternative exist, the use of eval() should be avoided (more for performance reasons than security reasons imho), it&#039;s become tiresome to constantly hear about the &quot;evils of eval&quot;.  Using that logic, mysql_query() is nearly as evil as eval() because it allows malicious code to be inserted into a script. 

In general, are there better choices than eval() for a given situation?  Yes.  Is eval() often a lazy way out?  Yes.  Does it have poor performance?  Yes.  But to call it evil because it&#039;s &quot;insecure&quot; is inaccurate.  In the wrong person&#039;s hands most anything can be considered &quot;evil&quot; because using unsanitized input opens the door wide open for any number of attacks.  Avoiding the use of eval() is generally good practice on a number of levels, but a competent developer should have no fears of using it because they should already be assured of the security of their user input.</description>
		<content:encoded><![CDATA[<p>&#8220;The moment you hear eval() the word “evil” should be on the tip of your tongue&#8221;</p>
<p>I believe more accurately, the moment you hear eval() the words &#8220;poor programmers&#8221; should be on the tip of your tongue.  While I believe in this case, and really any case where smarter alternative exist, the use of eval() should be avoided (more for performance reasons than security reasons imho), it&#8217;s become tiresome to constantly hear about the &#8220;evils of eval&#8221;.  Using that logic, mysql_query() is nearly as evil as eval() because it allows malicious code to be inserted into a script. </p>
<p>In general, are there better choices than eval() for a given situation?  Yes.  Is eval() often a lazy way out?  Yes.  Does it have poor performance?  Yes.  But to call it evil because it&#8217;s &#8220;insecure&#8221; is inaccurate.  In the wrong person&#8217;s hands most anything can be considered &#8220;evil&#8221; because using unsanitized input opens the door wide open for any number of attacks.  Avoiding the use of eval() is generally good practice on a number of levels, but a competent developer should have no fears of using it because they should already be assured of the security of their user input.</p>]]></content:encoded>
	</item>
</channel>
</rss>
