<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>include/scala/ch06/CheckPattern.scala</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2027,57 +2027,55 @@ assert(matches.isEmpty)
 
 // @@PLEAC@@_6.4
 //----------------------------------------------------------------------------------
-// TODO
-str = 'groovy.codehaus.org and www.aboutgroovy.com'
-re = '''(?x)          # to enable whitespace and comments
+val str = &quot;www.scala-lang.org and scala.sygneca.com&quot;
+val re = &quot;&quot;&quot;(?x)      # to enable whitespace and comments
       (               # capture the hostname in $1
         (?:           # these parens for grouping only
           (?! [-_] )  # lookahead for neither underscore nor dash
-          [\\w-] +    # hostname component
-          \\.         # and the domain dot
+          [\w-] +     # hostname component
+          \.          # and the domain dot
         ) +           # now repeat that whole thing a bunch of times
         [A-Za-z]      # next must be a letter
-        [\\w-] +      # now trailing domain part
+        [\w-] +       # now trailing domain part
       )               # end of $1 capture
-     '''
-
-finder = str =~ re
-out = str
-(0..&lt;finder.count).each{
-    adr = finder[it][0]
-    out = out.replaceAll(adr, &quot;$adr [${InetAddress.getByName(adr).hostAddress}]&quot;)
-}
-println out
-// =&gt; groovy.codehaus.org [63.246.7.187] and www.aboutgroovy.com [63.246.7.76]
+     &quot;&quot;&quot;.r            // the .r creates a scala.util.matching.Regex
+val withIp = re.findAllIn(str).map { s =&gt;
+  val ipaddr = java.net.InetAddress.getByName(s).getHostAddress()
+  s + &quot; [&quot; + ipaddr + &quot;]&quot;
+}.mkString(&quot; &quot;)
+println(withIp)
+// www.scala-lang.org [128.178.154.159] scala.sygneca.com [83.142.230.29]
 
 // to match whitespace or #-characters in an extended re you need to escape them.
-foo = 42
-str = 'blah #foo# blah'
-re = '''(?x)         # to enable whitespace and comments
-              \\#    # a pound sign
-              (\\w+) # the variable name
-              \\#    # another pound sign
-     '''
-finder = str =~ re
-found = finder[0]
-out = str.replaceAll(found[0], evaluate(found[1]).toString())
-assert out == 'blah 42 blah'
+val foo = &quot;42&quot;
+val str = &quot;blah #foo# blah&quot;
+val re = &quot;&quot;&quot;(?x)    # to enable whitespace and comments
+              \#    # a pound sign
+              (\w+) # the variable name
+              \#    # another pound sign
+         &quot;&quot;&quot;.r      // the .r creates a scala.util.matching.Regex
+val out = re.replaceAllIn(str, foo)
+assert(out == &quot;blah 42 blah&quot;)
 //----------------------------------------------------------------------------------
 
 // @@PLEAC@@_6.5
 //----------------------------------------------------------------------------------
 // TODO
-fish = 'One fish two fish red fish blue fish'
-expected = 'The third fish is a red one.'
-thirdFish = /(?:\w+\s+fish\s+){2}(\w+)\s+fish.*/
-assert expected == (fish.replaceAll(thirdFish, 'The third fish is a $1 one.'))
+val fish = &quot;One fish two fish red fish blue fish&quot;
+val expected = &quot;The third fish is a red one.&quot;
+val re = &quot;&quot;&quot;(\w+)\sfish\b&quot;&quot;&quot;.r
+// convert MatchIterator to Iterator[Match] to access groups,
+// drop the first 2 matches (we want the third fish),
+// get the match (next), get group 1
+val thirdFish = re.findAllIn(fish).matchData.drop(2).next.group(1)
+assert(expected == &quot;The third fish is a &quot; + thirdFish + &quot; one.&quot;)
 
-anyFish = /(\w+)\s+fish\b/
-finder = fish =~ anyFish
-// finder contains an array of matched groups
-// 2 = third one (index start at 0), 1 = matched word in group
-out = &quot;The third fish is a ${finder[2][1]} one.&quot;
-assert out == expected
+val fish = &quot;One fish two fish red fish blue fish&quot;
+val expected = &quot;The third fish is a red one.&quot;
+val re = &quot;&quot;&quot;(?:\w+\s+fish\s+){2}(\w+)\s+fish&quot;&quot;&quot;.r
+val thirdFish = re.findFirstMatchIn(fish).get.group(1)
+val out = &quot;The third fish is a &quot; + thirdFish + &quot; one.&quot;
+assert(expected == out)
 
 evens = []
 (0..&lt;finder.count).findAll{it%2!=0}.each{ evens += finder[it][1] }
@@ -2420,28 +2418,7 @@ assert input.findAll{ matchAll(it, ['cat$','^n.*']) }.size() == 0
 
 // @@PLEAC@@_6.11
 //----------------------------------------------------------------------------------
-// TODO
-// patternCheckingScript:
-prompt = '\n&gt; '
-print 'Enter patterns to check:' + prompt
-new BufferedReader(new InputStreamReader(System.in)).eachLine{ line -&gt;
-    try {
-        Pattern.compile(line)
-        print 'Valid' + prompt
-    } catch (java.util.regex.PatternSyntaxException ex) {
-        print 'Invalid pattern: ' + ex.message + prompt
-    }
-}
-// =&gt;
-// Enter patterns to check:
-// &gt; ab*.c
-// Valid
-// &gt; ^\s+[^a-z]*$
-// Valid
-// &gt; **
-// Invalid pattern: Dangling meta character '*' near index 0
-// **
-// ^
+// @@INCLUDE include/scala/ch06/CheckPattern.scala
 //----------------------------------------------------------------------------------
 
 // @@PLEAC@@_6.12</diff>
      <filename>pleac_scala.data</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>dc8fbed46393fdd55860099391ddeb00b2c84443</id>
    </parent>
  </parents>
  <author>
    <name>Michael Kebe</name>
    <email>michael.kebe@gmail.com</email>
  </author>
  <url>http://github.com/michaelkebe/pleac-scala/commit/2a200528c68fd1e708863524be4287585ddf06d6</url>
  <id>2a200528c68fd1e708863524be4287585ddf06d6</id>
  <committed-date>2009-07-02T12:52:39-07:00</committed-date>
  <authored-date>2009-07-02T12:52:39-07:00</authored-date>
  <message>PLEACs 6.4, 6.5, 6.11</message>
  <tree>235b71fd6914de8330b99178cc53fa0d31323e57</tree>
  <committer>
    <name>Michael Kebe</name>
    <email>michael.kebe@gmail.com</email>
  </committer>
</commit>
