<?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: Reading cookies the regular expression way</title>
	<atom:link href="http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/feed/" rel="self" type="application/rss+xml" />
	<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/</link>
	<description>Life at the bleeding edge (of web standards)</description>
	<lastBuildDate>Fri, 10 Feb 2012 07:25:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Constantine</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-2499</link>
		<dc:creator>Constantine</dc:creator>
		<pubDate>Thu, 30 Dec 2010 08:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-2499</guid>
		<description>Why would you need &quot;a shorter solution&quot; ? PPK code has only 22 lines, and you can easily minify it. 

Why use regexp, if you don&#039;t need to ? PPK&#039;s code is much easier for humans to read, and thus is much less error prone. Speed is not an issue, too, because you maximum cookie size is only 4KB. 

If you want &quot;more beautiful&quot; cookie handling code and no new functions in global scope - wrap it into object, or just use mainstream js libraries (http://mootools.net/docs/core/Utilities/Cookie)

 _________
p.s.: Some people, when confronted with a problem, think 
“I know, I&#039;ll use regular expressions.”   Now they have two problems.</description>
		<content:encoded><![CDATA[<p>Why would you need &#8220;a shorter solution&#8221; ? PPK code has only 22 lines, and you can easily minify it. </p>
<p>Why use regexp, if you don&#8217;t need to ? PPK&#8217;s code is much easier for humans to read, and thus is much less error prone. Speed is not an issue, too, because you maximum cookie size is only 4KB. </p>
<p>If you want &#8220;more beautiful&#8221; cookie handling code and no new functions in global scope &#8211; wrap it into object, or just use mainstream js libraries (<a href="http://mootools.net/docs/core/Utilities/Cookie" rel="nofollow">http://mootools.net/docs/core/Utilities/Cookie</a>)</p>
<p> _________<br />
p.s.: Some people, when confronted with a problem, think<br />
“I know, I&#8217;ll use regular expressions.”   Now they have two problems.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lea Verou</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-896</link>
		<dc:creator>Lea Verou</dc:creator>
		<pubDate>Sat, 16 Jan 2010 21:01:59 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-896</guid>
		<description>Have you actually tested that or are you just guessing? 
I think in most cases regular expressions are actually faster than string manipulation. Most JS frameworks even use them for simple case-insensitive string comparisions.</description>
		<content:encoded><![CDATA[<p>Have you actually tested that or are you just guessing?<br />
I think in most cases regular expressions are actually faster than string manipulation. Most JS frameworks even use them for simple case-insensitive string comparisions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: H</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-895</link>
		<dc:creator>H</dc:creator>
		<pubDate>Fri, 15 Jan 2010 18:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-895</guid>
		<description>There&#039;s a reason actually that a JS developer always avoids regular expressions, and that is code speed and performace. Perhaps it won&#039;t make much of a difference on your rig, but it all adds up making a website slower and slower on a netbook or older computer.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a reason actually that a JS developer always avoids regular expressions, and that is code speed and performace. Perhaps it won&#8217;t make much of a difference on your rig, but it all adds up making a website slower and slower on a netbook or older computer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lea Verou</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-836</link>
		<dc:creator>Lea Verou</dc:creator>
		<pubDate>Sun, 06 Dec 2009 12:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-836</guid>
		<description>You guys are both sooooo right!

Kangax, I can&#039;t believe I missed that, gosh!

Post updated. Thank you both!!</description>
		<content:encoded><![CDATA[<p>You guys are both sooooo right!</p>
<p>Kangax, I can&#8217;t believe I missed that, gosh!</p>
<p>Post updated. Thank you both!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-829</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Sun, 06 Dec 2009 03:58:40 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-829</guid>
		<description>It would probably make sense to escape name against regex meta characters. Looking at RFC2109, I see that characters allowed in cookie attribites are non-whitespace non-special ones (as defined in HTTP/1.1). HTTP/1.1 (RFC2068), in its turn, lists a set of special chars that appear to be not fully identical to special chars of regular expressions in ECMAScript. So... escaping names would be a good idea :)

And in fact, I just tried it in console:

document.cookie = &#039;foo&#124;bar=baz&#039;;
readCookie(&#039;foo&#124;bar&#039;); // &quot;undefined&quot;

document.cookie = &#039;foo*bar=baz&#039;;
readCookie(&#039;foo*bar&#039;); // null

PPK&#039;s `readCookie` returns proper &quot;baz&quot; in both cases (not saying that we should start using his solution now, just that we could do better with regex-based variant; say add this to a function — `name = name.replace(/([.*+?^=!:${}()&#124;[\]\/\\])/g, &#039;\\$1&#039;);`)</description>
		<content:encoded><![CDATA[<p>It would probably make sense to escape name against regex meta characters. Looking at RFC2109, I see that characters allowed in cookie attribites are non-whitespace non-special ones (as defined in HTTP/1.1). HTTP/1.1 (RFC2068), in its turn, lists a set of special chars that appear to be not fully identical to special chars of regular expressions in ECMAScript. So&#8230; escaping names would be a good idea <img src='http://lea.verou.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And in fact, I just tried it in console:</p>
<p>document.cookie = &#8216;foo|bar=baz&#8217;;<br />
readCookie(&#8216;foo|bar&#8217;); // &#8220;undefined&#8221;</p>
<p>document.cookie = &#8216;foo*bar=baz&#8217;;<br />
readCookie(&#8216;foo*bar&#8217;); // null</p>
<p>PPK&#8217;s `readCookie` returns proper &#8220;baz&#8221; in both cases (not saying that we should start using his solution now, just that we could do better with regex-based variant; say add this to a function — `name = name.replace(/([.*+?^=!:${}()|[\]\/\\])/g, &#8216;\\$1&#8242;);`)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/#comment-828</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 04 Dec 2009 23:58:01 +0000</pubDate>
		<guid isPermaLink="false">http://leaverou.me/?p=460#comment-828</guid>
		<description>Surely, the regular expression match will always return either null or the result array (and a match&#039;s length will never be zero). So, can&#039;t you simply return:

match &amp;&amp; unescape(match[1])

I agree with you about PPK&#039;s solution being a bit too verbose; PPK&#039;s JavaScript, IMO, is not his forte. He&#039;s always been a DOM Guru in my books... His JS never really impressed me. 

Regular expressions FTW</description>
		<content:encoded><![CDATA[<p>Surely, the regular expression match will always return either null or the result array (and a match&#8217;s length will never be zero). So, can&#8217;t you simply return:</p>
<p>match &amp;&amp; unescape(match[1])</p>
<p>I agree with you about PPK&#8217;s solution being a bit too verbose; PPK&#8217;s JavaScript, IMO, is not his forte. He&#8217;s always been a DOM Guru in my books&#8230; His JS never really impressed me. </p>
<p>Regular expressions FTW</p>
]]></content:encoded>
	</item>
</channel>
</rss>

