In [45]:
val regex = Array("+[a-z]", "-[b-d]", "+[a-d]")
Out[45]:
include a-z exlude b-d and include a-d => only 'a' admissibile
In [46]:
val r1 = regex.toSeq.map(x=> (x(0) == '+') -> x.tail)
Out[46]:
In [47]:
val input = "a"
val r2 = r1.map {
case(result, regex) => input.matches(regex) -> result
}
Out[47]:
In [48]:
val input = "b"
val r3 = r1.map {
case(result, regex) => input.matches(regex) -> result
}
Out[48]:
In [49]:
val input = "c"
val r4 = r1.map {
case(result, regex) => input.matches(regex) -> result
}
Out[49]:
In [55]:
r2.map(x => x._1 == x._2).reduce(_ && _)
r3.map(x => x._1 == x._2).reduce(_ && _)
r4.map(x => x._1 == x._2).reduce(_ && _)
Out[55]: