<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Using pattern matching with regular expressions in Scala</title>
	<atom:link href="http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/</link>
	<description>Follow me on Twitter: http://www.twitter.com/ikai</description>
	<lastBuildDate>Tue, 24 Jan 2012 19:17:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: jerm</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-458</link>
		<dc:creator><![CDATA[jerm]]></dc:creator>
		<pubDate>Tue, 25 Oct 2011 15:44:29 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-458</guid>
		<description><![CDATA[syntax highlighting please]]></description>
		<content:encoded><![CDATA[<p>syntax highlighting please</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Olin Atkinson</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-404</link>
		<dc:creator><![CDATA[Olin Atkinson]]></dc:creator>
		<pubDate>Fri, 24 Jun 2011 15:07:11 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-404</guid>
		<description><![CDATA[I think it would be important to to point out &quot;&quot;&quot;(?m) blab&quot;&quot;&quot; (?m) makes the regex a multiline and more importantly &quot;&quot;&quot;(?s).*mom.*&quot;&quot;&quot;  activates dotall matching (ie, matching &quot;.&quot; to new lines) which is very useful and hard to find in the doc and examples.]]></description>
		<content:encoded><![CDATA[<p>I think it would be important to to point out &#8220;&#8221;"(?m) blab&#8221;"&#8221; (?m) makes the regex a multiline and more importantly &#8220;&#8221;"(?s).*mom.*&#8221;"&#8221;  activates dotall matching (ie, matching &#8220;.&#8221; to new lines) which is very useful and hard to find in the doc and examples.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan W.</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-211</link>
		<dc:creator><![CDATA[Stefan W.]]></dc:creator>
		<pubDate>Sat, 07 Aug 2010 16:05:56 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-211</guid>
		<description><![CDATA[Who is &#039;&#039;you&#039;&#039;, Subhash? Which code doesn&#039;t work?
[code]
scala&gt; val alnu = &quot;&quot;&quot;foo ([a-zA-Z]+) ([0-9]+)&quot;&quot;&quot;.r 
alnu: scala.util.matching.Regex = foo ([a-zA-Z]+) ([0-9]+)

scala&gt; val alnu (str, num) =  &quot;foo bar 1234&quot;       
str: String = bar
num: String = 1234
[/code] works for me (2.8 final).

(a small hint on the website, how to format code, bold, cite, italic would be nice)

I don&#039;t understand the syntax. Normally, in the REPL, if I write 

val a = ...
val a = ...
 
the second a is hiding the first a - it&#039;s a new declaration, and I may write 

val a = 7
val a = &quot;seven&quot;

and the second line is, as if there never would have been the first line.]]></description>
		<content:encoded><![CDATA[<p>Who is &#8221;you&#8221;, Subhash? Which code doesn&#8217;t work?</p>
<pre class="brush: plain;">
scala&amp;gt; val alnu = &amp;quot;&amp;quot;&amp;quot;foo ([a-zA-Z]+) ([0-9]+)&amp;quot;&amp;quot;&amp;quot;.r
alnu: scala.util.matching.Regex = foo ([a-zA-Z]+) ([0-9]+)

scala&amp;gt; val alnu (str, num) =  &amp;quot;foo bar 1234&amp;quot;
str: String = bar
num: String = 1234
</pre>
<p> works for me (2.8 final).</p>
<p>(a small hint on the website, how to format code, bold, cite, italic would be nice)</p>
<p>I don&#8217;t understand the syntax. Normally, in the REPL, if I write </p>
<p>val a = &#8230;<br />
val a = &#8230;</p>
<p>the second a is hiding the first a &#8211; it&#8217;s a new declaration, and I may write </p>
<p>val a = 7<br />
val a = &#8220;seven&#8221;</p>
<p>and the second line is, as if there never would have been the first line.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Subhash Chandran</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-67</link>
		<dc:creator><![CDATA[Subhash Chandran]]></dc:creator>
		<pubDate>Fri, 26 Feb 2010 12:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-67</guid>
		<description><![CDATA[The syntax you have mentioned is not available in the recent versions of Scala.

See:

http://www.scala-lang.org/node/122
http://fileit.in/p/7]]></description>
		<content:encoded><![CDATA[<p>The syntax you have mentioned is not available in the recent versions of Scala.</p>
<p>See:</p>
<p><a href="http://www.scala-lang.org/node/122" rel="nofollow">http://www.scala-lang.org/node/122</a><br />
<a href="http://fileit.in/p/7" rel="nofollow">http://fileit.in/p/7</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jpitts</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-63</link>
		<dc:creator><![CDATA[jpitts]]></dc:creator>
		<pubDate>Mon, 25 Jan 2010 20:39:14 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-63</guid>
		<description><![CDATA[If (\d+) returns something that throws NumberFormatException, I think you&#039;d want to crow about it pretty loudly.]]></description>
		<content:encoded><![CDATA[<p>If (\d+) returns something that throws NumberFormatException, I think you&#8217;d want to crow about it pretty loudly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mein Blog &#187; Blog Archive &#187; Reguläre Ausdrücke, Pattern mathing</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-58</link>
		<dc:creator><![CDATA[mein Blog &#187; Blog Archive &#187; Reguläre Ausdrücke, Pattern mathing]]></dc:creator>
		<pubDate>Mon, 10 Aug 2009 18:00:17 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-58</guid>
		<description><![CDATA[[...] matching  extrahieren bsp [...]]]></description>
		<content:encoded><![CDATA[<p>[...] matching  extrahieren bsp [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Harrah</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-34</link>
		<dc:creator><![CDATA[Mark Harrah]]></dc:creator>
		<pubDate>Wed, 08 Apr 2009 14:52:17 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-34</guid>
		<description><![CDATA[You could do something like:

object I {
  def unapply(s: String): Option[Int] =
    try { Some(s.toInt) }
    catch { case _: NumberFormatException =&gt; None }
}

val LogEntry(I(totalTime), I(viewTime), I(dbTime), I(responseCode), uri) = line

totalTime: Int = 100
viewTime: Int = 25
dbTime: Int = 75
responseCode: Int = 200
uri: String =]]></description>
		<content:encoded><![CDATA[<p>You could do something like:</p>
<p>object I {<br />
  def unapply(s: String): Option[Int] =<br />
    try { Some(s.toInt) }<br />
    catch { case _: NumberFormatException =&gt; None }<br />
}</p>
<p>val LogEntry(I(totalTime), I(viewTime), I(dbTime), I(responseCode), uri) = line</p>
<p>totalTime: Int = 100<br />
viewTime: Int = 25<br />
dbTime: Int = 75<br />
responseCode: Int = 200<br />
uri: String =</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jherber</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-32</link>
		<dc:creator><![CDATA[jherber]]></dc:creator>
		<pubDate>Mon, 06 Apr 2009 02:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-32</guid>
		<description><![CDATA[Jorge, what&#039;s the advantage of the for comprehension over something less cerimonial?

object LogEntry {
  def unapply(line: String) = {
    val le(a,b,c,d,e) = line
    Some(a.toInt, b.toInt, c.toInt, d, e)
  }
}]]></description>
		<content:encoded><![CDATA[<p>Jorge, what&#8217;s the advantage of the for comprehension over something less cerimonial?</p>
<p>object LogEntry {<br />
  def unapply(line: String) = {<br />
    val le(a,b,c,d,e) = line<br />
    Some(a.toInt, b.toInt, c.toInt, d, e)<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jorge Ortiz</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-31</link>
		<dc:creator><![CDATA[Jorge Ortiz]]></dc:creator>
		<pubDate>Mon, 06 Apr 2009 00:11:34 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-31</guid>
		<description><![CDATA[Cool! I had no idea that Regex let you pattern match, which is pretty awesome.

Unfortunately, you can&#039;t make Regex return Ints directly. Types are a compile-time thing, and your pattern can be any arbitrary String constructed at run-time, so in general there&#039;s no way for the type-system to know what types of things you&#039;ll be matching on. However, with a little compile-time help you can achieve what you want:

  val le = &quot;&quot;&quot;Completed in (\d+)ms \(View: (\d+), DB: (\d+)\) \&#124; (\d+) OK \[http://app.domain.com(.*)\?.*&quot;&quot;&quot;.r
  val line = &quot;Completed in 100ms (View: 25, DB: 75) &#124; 200 OK [http://app.domain.com?params=here]&quot;
  object LogEntry {
    def unapply(line: String): Option[(Int, Int, Int, String, String)] =
      for (List(ttime, vtime, dtime, rc, uri) &lt;- le.unapplySeq(line))
        yield (ttime.toInt, vtime.toInt, dtime.toInt, rc, uri)
  }
  val LogEntry(totalTime, viewTime, dbTime, responseCode, uri) = line

  totalTime: Int = 100
  viewTime: Int = 25
  dbTime: Int = 75
  responseCode: String = 200
  uri: String =]]></description>
		<content:encoded><![CDATA[<p>Cool! I had no idea that Regex let you pattern match, which is pretty awesome.</p>
<p>Unfortunately, you can&#8217;t make Regex return Ints directly. Types are a compile-time thing, and your pattern can be any arbitrary String constructed at run-time, so in general there&#8217;s no way for the type-system to know what types of things you&#8217;ll be matching on. However, with a little compile-time help you can achieve what you want:</p>
<p>  val le = &#8220;&#8221;"Completed in (\d+)ms \(View: (\d+), DB: (\d+)\) \| (\d+) OK \[http://app.domain.com(.*)\?.*""".r<br />
  val line = "Completed in 100ms (View: 25, DB: 75) | 200 OK [http://app.domain.com?params=here]&#8221;<br />
  object LogEntry {<br />
    def unapply(line: String): Option[(Int, Int, Int, String, String)] =<br />
      for (List(ttime, vtime, dtime, rc, uri) &lt;- le.unapplySeq(line))<br />
        yield (ttime.toInt, vtime.toInt, dtime.toInt, rc, uri)<br />
  }<br />
  val LogEntry(totalTime, viewTime, dbTime, responseCode, uri) = line</p>
<p>  totalTime: Int = 100<br />
  viewTime: Int = 25<br />
  dbTime: Int = 75<br />
  responseCode: String = 200<br />
  uri: String =</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Channing Walton</title>
		<link>http://ikaisays.com/2009/04/04/using-pattern-matching-with-regular-expressions-in-scala/#comment-29</link>
		<dc:creator><![CDATA[Channing Walton]]></dc:creator>
		<pubDate>Sun, 05 Apr 2009 21:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://ikailansays.wordpress.com/?p=20#comment-29</guid>
		<description><![CDATA[Hi, here is some info about the unapply magic: http://www.scala-lang.org/node/112

I am puzzling over returning integers though...]]></description>
		<content:encoded><![CDATA[<p>Hi, here is some info about the unapply magic: <a href="http://www.scala-lang.org/node/112" rel="nofollow">http://www.scala-lang.org/node/112</a></p>
<p>I am puzzling over returning integers though&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

