<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
	>
<channel>
	<title>Comments on: Substrings in Ruby</title>
	<atom:link href="http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/</link>
	<description>life, music, religion and computers</description>
	<lastBuildDate>Tue, 24 Aug 2010 19:37:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Pistos</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-264796</link>
		<dc:creator>Pistos</dc:creator>
		<pubDate>Wed, 10 Jun 2009 13:07:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-264796</guid>
		<description>&lt;p&gt;Ruby 1.9 has &lt;a href=&quot;http://ruby-doc.org/core-1.9/classes/Regexp.html#M001067&quot; rel=&quot;nofollow&quot;&gt;named captures&lt;/a&gt;.  With this we can name capture groups in a regexp, and then local variables are assigned the captured strings.&lt;/p&gt;

&lt;pre lang=&quot;ruby&quot;&gt;
s = &quot;a123 bxyz&quot;
/a(?&lt;my_a&gt;\S+) +b(?&lt;my_b&gt;\S+)/ =~ s
my_a #=&gt; &quot;123&quot;
my_b #=&gt; &quot;xyz&quot;
&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Ruby 1.9 has <a href="http://ruby-doc.org/core-1.9/classes/Regexp.html#M001067" rel="nofollow">named captures</a>.  With this we can name capture groups in a regexp, and then local variables are assigned the captured strings.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">s = <span style="color:#996600;">&quot;a123 bxyz&quot;</span>
<span style="color:#006600; font-weight:bold;">/</span>a<span style="color:#006600; font-weight:bold;">&#40;</span>?<span style="color:#006600; font-weight:bold;">&lt;</span>my_a<span style="color:#006600; font-weight:bold;">&gt;</span>\S<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span>b<span style="color:#006600; font-weight:bold;">&#40;</span>?<span style="color:#006600; font-weight:bold;">&lt;</span>my_b<span style="color:#006600; font-weight:bold;">&gt;</span>\S<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span> =~ s
my_a <span style="color:#008000; font-style:italic;">#=&gt; &quot;123&quot;</span>
my_b <span style="color:#008000; font-style:italic;">#=&gt; &quot;xyz&quot;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Pistos</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-10</link>
		<dc:creator>Pistos</dc:creator>
		<pubDate>Mon, 04 Jun 2007 16:53:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-10</guid>
		<description>&lt;p&gt;Oh, I see.  Well... I guess we need to use &lt;pre&gt; and preview.  :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Oh, I see.  Well&#8230; I guess we need to use &lt;pre&gt; and preview.  <img src='http://blog.purepistos.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: manveru</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-9</link>
		<dc:creator>manveru</dc:creator>
		<pubDate>Mon, 04 Jun 2007 16:16:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-9</guid>
		<description>&lt;p&gt;Yes, but it still tries to remove the &lt;code&gt;\&lt;/code&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Yes, but it still tries to remove the <code>\</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pistos</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-8</link>
		<dc:creator>Pistos</dc:creator>
		<pubDate>Mon, 04 Jun 2007 15:38:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-8</guid>
		<description>&lt;p&gt;Hrm:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  test code
  right here.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Seems to work for me?  The way I&#039;m getting the highlighted code blocks is actually via the syntax highlight Wordpress plugin.  Add code blocks on my blog with &lt;pre lang=&quot;ruby&quot;&gt;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hrm:</p>
<pre><code>  test code
  right here.
</code></pre>
<p>Seems to work for me?  The way I&#8217;m getting the highlighted code blocks is actually via the syntax highlight Wordpress plugin.  Add code blocks on my blog with &lt;pre lang=&#8221;ruby&#8221;&gt;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: manveru</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-7</link>
		<dc:creator>manveru</dc:creator>
		<pubDate>Mon, 04 Jun 2007 15:11:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-7</guid>
		<description>&lt;p&gt;Yeah, i noticed that but didn&#039;t want to double-post.
To parse something like this i would use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  string = &#039;Monday, June 4, 2007&#039;
  format = &#039;%A, %B %d, %Y&#039;
  date = Date.strptime(string, format)
  puts date
  # =&gt; 2007-06-04
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But i get your point, groups would be quite handy at times instead of:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  &#039;Monday, June 4, 2007&#039;.match(/^(\\w+), (\\w+) (\\d+), (\\d+)/).captures
  # [&quot;Monday&quot;, &quot;June&quot;, &quot;4&quot;, &quot;2007&quot;]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This time i even previewed the post ;)
One thing i see though is that markdown doesn&#039;t work like the docs say, 4 spaces indentation should result in a code-block.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Yeah, i noticed that but didn&#8217;t want to double-post.<br />
To parse something like this i would use:</p>
<pre><code>  string = 'Monday, June 4, 2007'
  format = '%A, %B %d, %Y'
  date = Date.strptime(string, format)
  puts date
  # =&gt; 2007-06-04
</code></pre>
<p>But i get your point, groups would be quite handy at times instead of:</p>
<pre><code>  'Monday, June 4, 2007'.match(/^(\\w+), (\\w+) (\\d+), (\\d+)/).captures
  # ["Monday", "June", "4", "2007"]
</code></pre>
<p>This time i even previewed the post <img src='http://blog.purepistos.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
One thing i see though is that markdown doesn&#8217;t work like the docs say, 4 spaces indentation should result in a code-block.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pistos</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-5</link>
		<dc:creator>Pistos</dc:creator>
		<pubDate>Mon, 04 Jun 2007 13:20:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-5</guid>
		<description>&lt;p&gt;manveru:&lt;/p&gt;

&lt;p&gt;Your backslash got swallowed up by my &lt;a href=&quot;http://daringfireball.net/projects/markdown/syntax#backslash&quot; rel=&quot;nofollow&quot;&gt;Markdown&lt;/a&gt; plugin:&lt;/p&gt;

&lt;pre lang=&quot;ruby&quot;&gt;&#039;this is a&#039;.scan(/\w+/)[0,2]&lt;/pre&gt;

&lt;p&gt;But anyway: Thanks for pointing out this technique.  However, I&#039;m not sure it would let us grab arbitrary regexp groups, such as:&lt;/p&gt;

&lt;pre lang=&quot;ruby&quot;&gt;weekday, month, monthday, year =
&quot;Monday, June 4, 2007&quot;[
  /^(\w+), (\w+) (\d+), (\d+)/
]&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>manveru:</p>
<p>Your backslash got swallowed up by my <a href="http://daringfireball.net/projects/markdown/syntax#backslash" rel="nofollow">Markdown</a> plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#996600;">'this is a'</span>.<span style="color:#9900CC;">scan</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\w<span style="color:#006600; font-weight:bold;">+/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>But anyway: Thanks for pointing out this technique.  However, I&#8217;m not sure it would let us grab arbitrary regexp groups, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">weekday, month, monthday, year =
<span style="color:#996600;">&quot;Monday, June 4, 2007&quot;</span><span style="color:#006600; font-weight:bold;">&#91;</span>
  <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>\w<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006600; font-weight:bold;">&#40;</span>\w<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: manveru</title>
		<link>http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/comment-page-1/#comment-4</link>
		<dc:creator>manveru</dc:creator>
		<pubDate>Mon, 04 Jun 2007 09:35:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.purepistos.net/index.php/2007/06/03/substrings-in-ruby/#comment-4</guid>
		<description>&lt;p&gt;first, second = &#039;this is a&#039;.scan(/w+/)[0,2]&lt;/p&gt;

&lt;p&gt;[&quot;this&quot;, &quot;is&quot;]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>first, second = &#8216;this is a&#8217;.scan(/w+/)[0,2]</p>
<p>["this", "is"]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
