I found the following regex for matching comma separated numbers or ranges of numbers:
val reg = """^(\d+(-\d+)?)(,\s*(\d+(-\d+)?))*$""".r
While this does match valid strings, I only get one String out of it, instead of a list of strings, each corresponding to one of the separated entries. E.g.
reg.findAllIn("1-2, 3").map(s => s""""$s"""").toList
Gives
List("1-2, 3")
But I want:
List("1-2", "3")
The following comes closer:
val list = "1-2, 3" match {
case Reg(groups @ _*) => groups
case _ => Nil
}
list.map(s => s""""$s"""")
But it contains all sorts of 'garbage':
List("1-2", "-2", ", 3", "3", "null")