Below code is what I am using to parse a href link from a file :
def parseFile(){
val source = scala.io.Source.fromFile("C:\\Users\\Adrian\\Desktop\\parsefile.txt")
val lines = source.getLines
val Pattern = "\\s*(?i)href\\s*=\\s*(\\\"([^\"]*\")|'[^']*'|([^'\">\\s]+))"
for (line <- source.getLines) {
println(line)
line match {
case Pattern(c) => println(c)
case _ => None
}
}
source.close ()
}
A sample line from the parsefile :
<A HREF="www.google.com" title="test">test</A>
But I receive this Eclipse compile time error :
Multiple markers at this line
- not found: value c
- value Pattern is not a case class constructor, nor does it have an unapply/unapplySeq method
How should 'c' be declared in order to access the capture group String ?
I'm basing above code on accepted answer from this question :
How to pattern match using regular expression in Scala? where the code used is :
val Pattern = "([a-cA-C])".r
word.firstLetter match {
case Pattern(c) => c bound to capture group here
case _ =>
}
Any suggestions on a alternative methods to parse the file welcome.