Regex does not match in Kotlin

I can't figure out why this simple regex doesn't match anything. It always fails and throws an exception:

    val match = Regex("""\d+""").matchEntire("A123B")?: throw Exception("Regex fail")

      

+3


source to share


1 answer


You want to match all input with matchEntire

and a \d+

pattern:

fun matchEntire(input: CharSequence): MatchResult? (source)


Trying to match the entire CharSequence input to a pattern.
Returns a MatchResult instance if all input matches, or null otherwise.



However, it A123B

consists not only of numbers. If you need to find a partial match, use find

.

+3


source







All Articles