Try the following:
val intRegex = """(\d+)""".r val param = args(j) match { case intRegex(str) => str.toInt case _ => 0
You might want to use the argument parsing library.
Or, if you want to assign several parameters in one pass:
for (arg <- args) { arg match { case intRegex(arg) => param = arg.toInt case p if Files.exists(Paths.get(p)) => path = Paths.get(p) case _ =>
But this is a pretty ugly solution. I highly recommend you use some library, for example. Scopt ( https://github.com/scopt/scopt ). You can spend some time before you get used to it, but it’s good - you won’t reinvent the wheel next time :)
source share