Advertisements
I need regex that controls "00 XX 000 " pattern
please help
private fun isTransferDescriptionValid(description: String): Boolean {
val regex = "^[a-zA-Z0-9] [a-zA-Z0-9-/,. ][a-zA-Z0-9]\$".toRegex()
return description.matches(regex)
}
>Solution :
You can use, which would find 00 XX 000
\s
is a gensral placeholder for space
val regex = "^[0-9]{2}\s[a-zA-Z]{2}\s[0-9]{3}$".toRegex()
then there is also [:space:]
val regex = "^[0-9]{2}[[:space:]]{1}[a-zA-Z]{2}[[:space:]]{1}[0-9]{3}$".toRegex()
But sometimes only a literal space helps
val regex = "^[0-9]{2} [a-zA-Z]{2} [0-9]{3}$".toRegex()