Regex and Pattern Matching in Scala

Posted by Bruce Ferguson on Stack Overflow See other posts from Stack Overflow or by Bruce Ferguson
Published on 2011-01-08T22:50:17Z Indexed on 2011/01/08 22:53 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

I am not strong in regex, and pretty new to Scala. I would like to be able to find a match between the first letter of a word, and one of the letters in a group such as "ABC". In pseudocode, this might look something like:

case Process(word) =>
   word.firstLetter match {
      case([a-c][A-C]) =>
      case _ =>
   }
}

but I don't know how to grab the first letter in Scala instead of Java, how to express the regular expression properly, nor if it's possible to do this within a case class. Any suggestions? Thanks in advance.

Bruce

© Stack Overflow or respective owner

Related posts about regex

Related posts about scala