I'm trying to figure out proper way of working with RegEx in Kotlin. After working with RegEx to no good I found the link at https://developer.android.com/reference/kotlin/java/util/regex/Pattern shows something equivalent to RegEx and I tried various tests as in the below and got true only for the first three.
But I think many other candidates should show true. Can anyone help me understand what the problem is?
var patterns = arrayOf (
arrayOf ("abc","abc"), // true
arrayOf ("abc","cba"), // true
arrayOf ("abc","aaa"), // true
arrayOf ("[a-c]","abc"), // false, but should be true
arrayOf ("[a-c]","abcd"), // false, OK
arrayOf ("""[a-c]""","abc"), // false
arrayOf ("""[a-c]""","abcd"), // false
arrayOf ("\\d","11"), // false
arrayOf ("[\\d]","11"), // false, should be true [\d] led to error in compile
arrayOf ("[a-z]","abc"), // false, should be true
arrayOf ("[a-zA-Z]","abcZBD") // flase, should be true
)
for (i in 0 until patterns.size){
Log.d(TAG, "${i} >> ${Pattern.matches(patterns[i][0],patterns[i][0])}")
}
Aucun commentaire:
Enregistrer un commentaire