<?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>Fri, 26 Feb 2010 12:11:39 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>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>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>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>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>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>[...] 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>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>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>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>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>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>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>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>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>
