Question: How can I do pattern matching to match all elements up to the last element?

For example, suppose I have this unapplySeq:

```
object MyObject {
  def unapplySeq(money: String): Option[List[Char]] = {
    val amount = money.trim.toList
    if (amount.isEmpty) None
    else
      Some(amount)
  }
}

```

And I try the following match:

```
"12.15 €" match {
    case MyObject('$' , last @ _*) =>   s"${last.mkString} dollars"

    // this is wrong
    case MyObject(first @ _*, '€') =>   s"${last.mkString} euro"  

    case _ => "Unknown format"
}

```

I can do this for US amounts where I pass in $120.10 for example, but how do I rewrite the second case to match the euro string where the symbol is at the end?

Answer: 
This would be pretty straightforward with Regex

```
def currency(s: String) {
  val dollar = """\$(.+)""".r
  val euro = """(.+)€""".r  
  s match {
    case dollar(amt) => println(amt + " dollars")
    case euro(amt) => println(amt + " euros")
    case _ => println("unknown currency")
  }
}

scala> currency("$1346.00")
1346.00 dollars

scala> currency("1346.00€")
1346.00 euros

```
Possibly, regexes are overkill to express "startsWith" and "endsWith".

A simple extractor does the job, but listifying Strings to do it is a notch below stringifying Lists.

```
scala> object Currency { def unapply(s: String): Option[(Char, String)] =
     | if (s.head == '$') Some('$',s.tail)
     | else if (s.last == '€') Some('€',s.init) else None }
defined object Currency

scala> def currency(s: String) = s match { case Currency(c, amt) => s"$amt of $c" case _ => "unknown" }
currency: (s: String)String

scala> currency("$120.10")
res2: String = 120.10 of $

scala> currency("1346.00€")
res3: String = 1346.00 of €

```

No doubt you'd really extract a currency enum and a number.