includeExcludeRegex


In [45]:
val regex = Array("+[a-z]", "-[b-d]", "+[a-d]")


Out[45]:
regex: Array[String] = Array("+[a-z]", "-[b-d]", "+[a-d]")

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]:
r1: Seq[(Boolean, String)] = ArrayBuffer((true, "[a-z]"), (false, "[b-d]"), (true, "[a-d]"))

In [47]:
val input = "a"
val r2 = r1.map { 
    case(result, regex) => input.matches(regex) -> result
}


Out[47]:
input: String = "a"
r2: Seq[(Boolean, Boolean)] = ArrayBuffer((true, true), (false, false), (true, true))

In [48]:
val input = "b"
val r3 = r1.map { 
    case(result, regex) => input.matches(regex) -> result
}


Out[48]:
input: String = "b"
r3: Seq[(Boolean, Boolean)] = ArrayBuffer((true, true), (true, false), (true, true))

In [49]:
val input = "c"
val r4 = r1.map { 
    case(result, regex) => input.matches(regex) -> result
}


Out[49]:
input: String = "c"
r4: Seq[(Boolean, Boolean)] = ArrayBuffer((true, true), (true, false), (true, true))

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]:
res54_0: Boolean = true
res54_1: Boolean = false
res54_2: Boolean = false