I have a Scala method that currently accepts input and matches it against a regex:
def valiateMap(mapDef : String) : String = {
val mapRegex = "map<([int,string,date]),([int,string,date])>".r
mapDef match {
case mapRegex(keyGroup, valueGroup) => "Yes, we have a match!"
case _ => "'Fraid not."
}
}
So as you can see, passing in various values will have the following results:
validateMap("map<int,date>")
-> "Yes, we have a match!"validateMap("fizzbuzz")
-> "'Fraid not."validateMap("map<int,fizz>")
-> "'Fraid not." (fizz is not valid for the regex)
Now I need to make this regex recursive, so that the "valueGroup
" (2nd group) value can itself be a map, following the same regex as above. And that map could also have a map for its value, which would need to abide by the same regex. So on and so forth.
So I need to modify the regex (and/or the code) to handle input like:
validateMap("map<int,map<date,string>>")
-> "Yes, we have a match!"validateMap("map<int,map<int,map<int,string>>>")
-> "Yes, we have a match!"validateMap("map<int,map<fizz,date>>")
-> "'Fraid not."
The kicker is that this needs to be (potentially) infinitely recursive, and handle any number of inner-nested maps.
Any ideas as to how I could accomplish this?