<?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="https://programmingzen.com/how-to-parse-numbers-in-a-string/feed/" rel="self" type="application/rss+xml" />
	<link>https://programmingzen.com/how-to-parse-numbers-in-a-string/</link>
	<description>Meditations on programming, startups, and technology</description>
	<lastBuildDate>Sun, 05 Feb 2006 11:40:00 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Tore Darell		</title>
		<link>https://programmingzen.com/how-to-parse-numbers-in-a-string/#comment-61</link>

		<dc:creator><![CDATA[Tore Darell]]></dc:creator>
		<pubDate>Mon, 30 Nov -0001 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><![CDATA[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>https://programmingzen.com/how-to-parse-numbers-in-a-string/#comment-62</link>

		<dc:creator><![CDATA[federico]]></dc:creator>
		<pubDate>Mon, 30 Nov -0001 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><![CDATA[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? 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Antonio Cangiano		</title>
		<link>https://programmingzen.com/how-to-parse-numbers-in-a-string/#comment-63</link>

		<dc:creator><![CDATA[Antonio Cangiano]]></dc:creator>
		<pubDate>Mon, 30 Nov -0001 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><![CDATA[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. 😉</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
