scala/ScalaBook/chapter-02/regex2.scala
import java.util.regex.{Pattern,Matcher}
var INPUT = "Αναστασία"
var found = false
val p1 = Pattern.compile(".*α")
val p2 = Pattern.compile(".*?α")
val p3 = Pattern.compile(".*+α")
var m1 = p1.matcher(INPUT)
println("Greedy")
while ( m1.find() ) {
print("I found the text \""+ m1.group())
print("\" starting at index " + m1.start())
println(" and ending at index " + m1.end())
found = true
}
if (!found)
println("No match found.\n")
found = false
println("Reluctant")
var m2 = p2.matcher(INPUT)
while ( m2.find() ) {
print("I found the text \""+ m2.group())
print("\" starting at index " + m2.start())
println(" and ending at index " + m2.end())
found = true
}
if (!found)
println("No match found.\n")
found = false
println("Possessive")
var m3 = p3.matcher(INPUT)
while ( m3.find() ) {
print("I found the text \""+ m3.group())
print("\" starting at index " + m3.start())
println(" and ending at index " + m3.end())
found = true
}
if (!found)
println("No match found.\n")