<?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: How to parse decimal numbers within a string</title>
	<atom:link href="http://programmingzen.com/2006/02/05/how-to-parse-numbers-in-a-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingzen.com/2006/02/05/how-to-parse-numbers-in-a-string/</link>
	<description>By Antonio Cangiano, Software Engineer &#38; Technical Evangelist at IBM</description>
	<lastBuildDate>Sat, 31 Jul 2010 03:23:54 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Tore Darell</title>
		<link>http://programmingzen.com/2006/02/05/how-to-parse-numbers-in-a-string/#comment-61</link>
		<dc:creator>Tore Darell</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://72.52.169.158/~antonioc/2006/02/05/how-to-parse-numbers-in-a-string/#comment-61</guid>
		<description>Nice. I found I had to make the matching group in the second regex non-capturing, though, as the String#scan method would only return arrays of group matches if they&#039;re present (containing nil if it wasn&#039;t scientific notation), but this worked on both &quot;classic&quot; numbers and numbers written with scientific notation:

&lt;pre&gt;&lt;code&gt;
    numbers = s.scan /[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/
&lt;/code&gt;&lt;/pre&gt;

And, to easily turn the Strings returned by String#scan in to Integers and Floats, just do

&lt;pre&gt;&lt;code&gt;
    numbers.map{&#124;n&#124; n.include?(&#039;.&#039;) ? n.to_f : n.to_i}
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Nice. I found I had to make the matching group in the second regex non-capturing, though, as the String#scan method would only return arrays of group matches if they&#8217;re present (containing nil if it wasn&#8217;t scientific notation), but this worked on both &#8220;classic&#8221; numbers and numbers written with scientific notation:</p>
<pre><code>
    numbers = s.scan /[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/
</code></pre>
<p>And, to easily turn the Strings returned by String#scan in to Integers and Floats, just do</p>
<pre><code>
    numbers.map{|n| n.include?('.') ? n.to_f : n.to_i}
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: federico</title>
		<link>http://programmingzen.com/2006/02/05/how-to-parse-numbers-in-a-string/#comment-62</link>
		<dc:creator>federico</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://72.52.169.158/~antonioc/2006/02/05/how-to-parse-numbers-in-a-string/#comment-62</guid>
		<description>Isn&#039;t more correct something like:

/[+-]?\d+(\.\d+)?/

Since your regexp will match something like .5 without any digit before the decimal point... or it&#039;s that what you want? :)</description>
		<content:encoded><![CDATA[<p>Isn&#8217;t more correct something like:</p>
<p>/[+-]?\d+(\.\d+)?/</p>
<p>Since your regexp will match something like .5 without any digit before the decimal point&#8230; or it&#8217;s that what you want? <img src='http://programmingzen.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antonio Cangiano</title>
		<link>http://programmingzen.com/2006/02/05/how-to-parse-numbers-in-a-string/#comment-63</link>
		<dc:creator>Antonio Cangiano</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://72.52.169.158/~antonioc/2006/02/05/how-to-parse-numbers-in-a-string/#comment-63</guid>
		<description>Hi Federico,
.5 is consider 0.5 in several countries. It is intentional. ;-)</description>
		<content:encoded><![CDATA[<p>Hi Federico,<br />
.5 is consider 0.5 in several countries. It is intentional. <img src='http://programmingzen.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
