Issue
I want to use regex in kotlin to allow only this kind of strings each strings is length of 15 and can be of any long I just kept 3 numbers as example.
"123456789101236 \n 123456789101237 \n 123456789101238"
Solution
You may use the following regex pattern:
\d{15}(?: \n \d{15})*
This assumes that you want only numbers of length 15. If you want any character, then use .{15}
in place of \d{15}
.
Kotlin code:
val input = "123456789101236 \n 123456789101237 \n 123456789101238";
val regex = "\\d{15}(?: \n \\d{15})*".toRegex()
if (regex.matches(input)) {
println("MATCH") // prints MATCH
}
Answered By - Tim Biegeleisen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.